1.

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.



Discussion

No Comment Found

Related InterviewSolutions