Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

51.

Which among the following is false?(a) Constructor can’t be overloaded in Kotlin(b) Constructors can’t be called recursively in java(c) Constructors can be overloaded in C++(d) Constructors overloading depends on different signaturesThis question was addressed to me during an interview.The query is from Overloading Constructors topic in division Constructors and Destructors of Object Oriented Programming

Answer»

The correct option is (a) Constructor can’t be overloaded in KOTLIN

The EXPLANATION: Kotlin LANGUAGE allows constructor OVERLOADING. This is a basic feature for the constructors. The constructor overloading allows the OBJECT to be initialized according to the user.

52.

Which is correct syntax?(a) classname objectname= new() integer;(b) classname objectname= new classname;(c) classname objectname= new classname();(d) classname objectname= new() classname();I have been asked this question in a national level competition.Question is from Overloading Constructors in division Constructors and Destructors of Object Oriented Programming

Answer»

Right answer is (c) classname objectname= new classname();

The best I can explain: The syntax for object CREATING in java with calling a constructor for is it is as in OPTION c. The syntax must CONTAIN the classname FOLLOWED by the object name. The keyword new must be used and then the constructor CALL with or without the parameters as required.

53.

Which among the following best describes the constructors?(a) A function which is called whenever an object is referenced(b) A function which is called whenever an object is created to initialize the members(c) A function which is called whenever an object is assigned to copy the values(d) A function which is called whenever an object is to be given values for membersThe question was asked by my school principal while I was bunking the class.This key question is from Execution of Constructor or Destructor topic in chapter Constructors and Destructors of Object Oriented Programming

Answer»

Correct choice is (b) A function which is called whenever an object is created to initialize the members

Easy EXPLANATION - The constructors are special type of functions which are called whenever an object is created. This is to initialize the DATA members of the CLASS. The constructor allocates memory SPACE for all the data members.

54.

Which among the following best describes destructor?(a) A function which is called just before the objects are destroyed(b) A function which is called after each reference to the object(c) A function which is called after termination of the program(d) A function which is called before calling any member functionI have been asked this question in an online quiz.I would like to ask this question from Execution of Constructor or Destructor in section Constructors and Destructors of Object Oriented Programming

Answer»

Correct choice is (a) A FUNCTION which is called just before the objects are destroyed

Best EXPLANATION: The DESTRUCTORS are special functions which are called just before an object is destroyed. This functions is responsible to free all the ALLOCATED resources to the object. Objects are destroyed WHENEVER those go out of scope.

55.

Which among the following represents correct constructor?(a) ()classname(b) ~classname()(c) –classname()(d) classname()I have been asked this question during a job interview.I'm obligated to ask this question of Execution of Constructor or Destructor topic in chapter Constructors and Destructors of Object Oriented Programming

Answer»

Right OPTION is (d) CLASSNAME()

The EXPLANATION: The constructors must contain only the CLASS name. The class name is followed by the blank parenthesis or we can have PARAMETERS if some values are to be passed.

56.

Which among the following is correct syntax for the destructors?(a) classname()(b) ()classname(c) ~classname()(d) -classname()I got this question during an internship interview.I'm obligated to ask this question of Execution of Constructor or Destructor in section Constructors and Destructors of Object Oriented Programming

Answer»

Correct answer is (c) ~classname()

The explanation: The destructor MUST have same NAME as that of the CORRESPONDING CLASS. The class name should be preceded by the TILDE symbol (~).

57.

Which among the following is true?(a) First the constructor of parent classes are called in sequence of inheritance(b) First the constructor of child classes are called in the sequence of inheritance(c) First constructor called is of the object being created(d) Constructors are called randomlyI have been asked this question during an internship interview.The query is from Execution of Constructor or Destructor in division Constructors and Destructors of Object Oriented Programming

Answer»

Right option is (a) First the CONSTRUCTOR of parent classes are called in sequence of INHERITANCE

To explain: First the constructor of parent CLASS are called. The order in which the parent class CONSTRUCTORS are called is same in the sequence of inheritance used.

58.

What is the sequence of destructors call?(a) Same order as that of the constructors call(b) Random order(c) According to the priority(d) Revere of the order of constructor callI got this question during an interview for a job.This key question is from Execution of Constructor or Destructor in division Constructors and Destructors of Object Oriented Programming

Answer»

Right OPTION is (d) REVERE of the order of CONSTRUCTOR call

To EXPLAIN: The destructors are called in the reverse order as that of the constructors being called. This is DONE to ensure that all the resources are released in sequence. That is, the derived class destructors will be called first.

59.

The destructors _____________________(a) Can have maximum one argument(b) Can’t have any argument(c) Can have more than one argument(d) Can’t have more than 3 argumentsI have been asked this question in final exam.The query is from Execution of Constructor or Destructor topic in division Constructors and Destructors of Object Oriented Programming

Answer»

Right choice is (b) Can’t have any argument

Easiest explanation - The destructors doesn’t have any arguments. The destructors have to be called implicitly WHENEVER an object goes out of SCOPE. The USER can’t pass argument to the IMPLICIT CALL.

60.

Destructor calls ________________ (C++)(a) Are only implicit(b) Are only explicit(c) Can be implicit or explicit(d) Are made at end of program onlyThis question was posed to me by my college director while I was bunking the class.My doubt stems from Execution of Constructor or Destructor in section Constructors and Destructors of Object Oriented Programming

Answer»

Right option is (c) Can be implicit or explicit

Easy explanation - The destructors are usually called implicitly whenever an object GOES out of SCOPE. The destructors can also be called explicitly if REQUIRED. The CALL must be MADE, implicitly or explicitly.

61.

Number of destructors called are ____________(a) Always equal to number of constructors called(b) Always less than the number of constructors called(c) Always greater than the number of constructors called(d) Always less than or equal to number of constructorsThis question was addressed to me during a job interview.I need to ask this question from Execution of Constructor or Destructor in section Constructors and Destructors of Object Oriented Programming

Answer»

Right answer is (a) ALWAYS equal to NUMBER of CONSTRUCTORS called

The explanation is: DESTRUCTOR will be called only to free the resources allocated for an object. The resources are allocated only the constructor for an object is called.

62.

For explicit call _________________(a) The destructor must be private(b) The destructor must be public(c) The destructor must be protected(d) The destructor must be defined outside the classThis question was addressed to me in homework.Query is from Execution of Constructor or Destructor in division Constructors and Destructors of Object Oriented Programming

Answer»

Right answer is (B) The destructor must be public

The BEST explanation: The destructor must be public for explicit calls. If it is made PRIVATE or PROTECTED then it won’t be ACCESSIBLE outside the class. There is no restriction of definition the destructor outside the class.

63.

If a class have 4 constructors then it must have 4 destructors also.(a) True(b) FalseThe question was posed to me during an internship interview.My doubt is from Execution of Constructor or Destructor topic in section Constructors and Destructors of Object Oriented Programming

Answer»

Right OPTION is (b) False

Explanation: EVEN if the CLASS have 4 constructors, only one would be used. And only one DESTRUCTOR is allowed.

64.

Which among the following is true for destructors?(a) Destructors can be overloaded(b) Destructors can be define more than one time(c) Destructors can’t be overloaded(d) Destructors are overloaded in derived classesThe question was posed to me during an interview.The question is from Execution of Constructor or Destructor in division Constructors and Destructors of Object Oriented Programming

Answer»

Correct choice is (c) Destructors can’t be overloaded

The best I can explain: The destructors can NEVER be overloaded. The destructors doesn’t have arguments. And to get overloaded, they MUST have different SIGNATURE. This is not POSSIBLE if arguments are not allowed.

65.

The constructor _____________(a) Have a return type(b) May have a return type(c) Of derived classes have return type(d) Doesn’t have a return typeI have been asked this question in an online quiz.The above asked question is from Execution of Constructor or Destructor in division Constructors and Destructors of Object Oriented Programming

Answer» RIGHT option is (d) Doesn’t have a return type

Explanation: The CONSTRUCTORS doesn’t have any return type. The constructors are intended to allocate the resources for the OBJECT. MEMORY spaces are to be FINALIZED.
66.

The destructors ____________(a) Have a return type(b) May have a return type(c) Of derived classes have return type(d) Doesn’t have a return typeI have been asked this question during a job interview.My question is based upon Execution of Constructor or Destructor topic in portion Constructors and Destructors of Object Oriented Programming

Answer»

The correct choice is (d) Doesn’t have a return type

The best explanation: The destructors are intended to FREE the memory space. And all the resources that were ALLOCATED for the OBJECT. The return VALUE is not supported SINCE only memory has to be made free.

67.

The destructor can be called before the constructor if required.(a) True(b) FalseThis question was posed to me in an online interview.Enquiry is from Execution of Constructor or Destructor in chapter Constructors and Destructors of Object Oriented Programming

Answer»

The correct choice is (b) False

Best EXPLANATION: The destructors can be called only after the constructor CALLS. It is not a MANDATORY rule but the DELETION can only take place if there is something CREATED using the constructor.

68.

Which among the following describes a destructor?(a) A special function that is called to free the resources, acquired by the object(b) A special function that is called to delete the class(c) A special function that is called anytime to delete an object(d) A special function that is called to delete all the objects of a classI have been asked this question during an interview.The above asked question is from Destructors topic in section Constructors and Destructors of Object Oriented Programming

Answer»

Right ANSWER is (a) A special function that is called to free the resources, acquired by the object

Easiest explanation - It is USED to free the resources that the object might had used in its LIFESPAN. The DESTRUCTORS are called implicitly whenever an object’s life ends.

69.

When a destructor is called?(a) After the end of object life(b) Anytime in between object’s lifespan(c) At end of whole program(d) Just before the end of object lifeThis question was posed to me in an interview for job.I need to ask this question from Destructors topic in portion Constructors and Destructors of Object Oriented Programming

Answer»

Correct option is (d) Just before the end of OBJECT life

Easiest explanation - The DESTRUCTOR is called just before the object go out of scope or just before its life ends. This is done to ensure that all the resources reserved for the object are USED and at last, are made free for others.

70.

Which among the following is correct for abstract class destructors?(a) It doesn’t have destructors(b) It has destructors(c) It may or may not have destructors(d) It contains an implicit destructorI have been asked this question in an interview for internship.My enquiry is from Destructors in division Constructors and Destructors of Object Oriented Programming

Answer»

Right ANSWER is (a) It doesn’t have destructors

The explanation is: It doesn’t have destructors. Since an ABSTRACT class don’t have CONSTRUCTORS, and hence can’t have instances. Having this case, the abstract CLASSES don’t have destructors too, because that would be of no use here.

71.

If in multiple inheritance, class C inherits class B, and Class B inherits class A. In which sequence are their destructors called if an object of class C was declared?(a) ~C() then ~B() then ~A()(b) ~B() then ~C() then ~A()(c) ~A() then ~B() then ~C()(d) ~C() then ~A() then ~B()This question was addressed to me in exam.The doubt is from Destructors in section Constructors and Destructors of Object Oriented Programming

Answer»

Correct choice is (a) ~C() then ~B() then ~A()

The best I can EXPLAIN: The destructors are always called in the reverse order of how the CONSTRUCTORS were called. Here class A constructor WOULD have been created FIRST if Class C object is declared. Hence class A destructor is called at last.

72.

When is the destructor of a global object called?(a) Just before end of program(b) Just after end of program(c) With the end of program(d) Anytime when object is not neededI got this question in an online quiz.This intriguing question originated from Destructors topic in section Constructors and Destructors of Object Oriented Programming

Answer»

Right answer is (a) Just before end of program

The BEST I can explain: This is because the lifespan of global object is from start of the program, TILL the end of the program. And hence program end is the end of global object too. Just before the end of program, the destructor will be CALLED to free the ACQUIRED resources by the objects.

73.

How the constructors and destructors can be differentiated?(a) Destructor have a return type but constructor doesn’t(b) Destructors can’t be defined by the programmer, but constructors can be defined(c) Destructors are preceded with a tilde (~) symbol, and constructor doesn’t(d) Destructors are same as constructors in syntaxI had been asked this question during an online interview.The origin of the question is Destructors topic in chapter Constructors and Destructors of Object Oriented Programming

Answer»

Correct option is (C) Destructors are preceded with a tilde (~) symbol, and constructor doesn’t

The best EXPLANATION: The destructors are preceded with the tilde (~) symbol. The NAME is same as that of the class. These also doesn’t have any return type.

74.

Destructors doesn’t accept parameters.(a) True(b) FalseThe question was posed to me in an interview.This intriguing question originated from Destructors topic in chapter Constructors and Destructors of Object Oriented Programming

Answer» RIGHT ANSWER is (a) True

The BEST explanation: The destructors doesn’t accept the ARGUMENTS. Those are just used to free up the resources.
75.

Destructors can be ________(a) Abstract type(b) Virtual(c) Void(d) Any type depending on situationThis question was posed to me in an online quiz.This question is from Destructors topic in portion Constructors and Destructors of Object Oriented Programming

Answer»

Correct option is (b) Virtual

Easiest explanation - The destructors can be virtual. It is actually advised to keep the destructors virtual ALWAYS. This is DONE to suppress the problems that may ARISE if inheritance is involved.

76.

Global destructors execute in ___________ order after main function is terminated.(a) Sequential(b) Random(c) Reverse(d) Depending on priorityThis question was posed to me in semester exam.The query is from Destructors topic in section Constructors and Destructors of Object Oriented Programming

Answer»

Right option is (c) REVERSE

Easiest explanation - The destructors are ALWAYS called in reverse order no matter which destructor it is. This is done to ensure that all the RESOURCES are able to get free. And no RESOURCE is KEPT busy.

77.

When is it advised to have user defined destructor?(a) When class contains some pointer to memory allocated in class(b) When a class contains static variables(c) When a class contains static functions(d) When a class is inheriting another class onlyThis question was addressed to me during an online exam.Origin of the question is Destructors topic in division Constructors and Destructors of Object Oriented Programming

Answer»

The correct answer is (a) When class contains some pointer to MEMORY allocated in class

Explanation: This is always advised to have user defined destructor when pointers are involved in class. This is usually done to ensure that the memory, that was allocated dynamically, GETS FREE after use and doesn’t cause memory LEAK.

78.

Which among the following is correct for the destructors concept?(a) Destructors can be overloaded(b) Destructors can have only one parameter at maximum(c) Destructors are always called after object goes out of scope(d) There can be only one destructor in a classThe question was asked in an interview.I would like to ask this question from Destructors in section Constructors and Destructors of Object Oriented Programming

Answer»

The CORRECT choice is (d) There can be only one destructor in a class

The explanation is: This is so because the DESTRUCTORS can’t be OVERLOADED. And the destructor must have the same name as that of class with a tilde symbol preceding the name of the destructor. Hence there can be only one destructor in a class. Since more than one FUNCTION with same name and signature can’t be PRESENT in same scope.

79.

When an object is passed to a function, its copy is made in the function and then ______________(a) The destructor of the copy is called when function is returned(b) The destructor is never called in this case(c) The destructor is called but it is always implicit(d) The destructor must be user definedThe question was posed to me in semester exam.Enquiry is from Destructors topic in division Constructors and Destructors of Object Oriented Programming

Answer» CORRECT option is (a) The destructor of the copy is called when function is returned

The explanation: When an OBJECT is passed to a function, its copy is made in the function. This copy acts as a real object till the function is live. When the function is returned, the copy’s destructor is called to FREE the resources held by it.
80.

What happens when an object is passed by reference?(a) Destructor is not called(b) Destructor is called at end of function(c) Destructor is called when function is out of scope(d) Destructor is called when called explicitlyThe question was posed to me in final exam.Query is from Destructors in chapter Constructors and Destructors of Object Oriented Programming

Answer»

Right option is (a) Destructor is not called

The best I can explain: The destructor is never called in this situation. The CONCEPT is that when an object is passed by REFERENCE to the function, the CONSTRUCTOR is not called, but only the main object will be used. Hence no destructor will be called at end of function.