Derived class having constructor & destructor - Features - Inheritance

Q.  In case of inheritance where both base and derived class are having constructor and destructor, then which if the following are true ?

1. Constructors are executed in their order of derivation
2. Constructors are executed in reverse order of derivation
3. Destructors are executed in their order of derivation
4. Destructors are executed in reverse order of derivation

- Published on 17 Jul 15

a. Only 2 ,4
b. Only 1 , 3
c. Only 1 , 4
d. Only 2, 3

ANSWER: Only 1 , 4
 

    Discussion

  • Nihal   -Posted on 08 Oct 15
    In multilevel inheritance constructor are always executed from most base class to derived class and destructor are executed from derived class to base class or we can say Destructors are executed in reverse order of derivation.

Post your comment / Share knowledge


Enter the code shown above:

(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)