1.

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.



Discussion

No Comment Found

Related InterviewSolutions