What is the order of destructors called in a polymorphism hierarchy

A) Starts with derived class ends at base class
B) Starts with base class ends at derived class
C) The destructor of base can not becalled
D) Randomly
Explanation: Uses Bottomup approach while calling Destructors from derived class

Showing Answers 1 - 5 of 5 Answers

samiksc

  • Jan 10th, 2006
 

Answer (A) is correct. Destructors are called in reverse order of constructors. First destructor of most derived class is called followed by its parent's destructor and so on till the topmost class in the hierarchy.

You don't have control over when the first destructor will be called, since it is determined by the garbage collector. Sometime after the object goes out of scope GC calls the destructor, then its parent's destructor and so on.

When a program terminates definitely all object's destructors are called.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions