Explain the Constructor and destructor invocation order in case of multi level inheritance.

How to write this program?

We need a multi level inheritance.

And we know that multi level inheritance is as follows

At first, we will have a class name say “student”.

Then we will derive “test” from “student” (assume).

Then we will derive “result” from “test”.

It can be better represented as follows.

AND the constructor invocation of multi level inheritance can be represented as follows-: [SAME AS ABOVE FIGURE]

Now, the concept of multi level inheritance is clear,

Then we will create constructors(as well as destructors) inside each classes say x,y,and z classes.

The rule of constructor invocation in multi level inheritance is shown in figure below-:

So, our output must be like, first base class constructor, then derived1 class constructor and then derived2 class constructor.

Source Code-:


Base3 class constructor

derived1 class constructor

derived2 class constructor

derived2 class destructor

derived1 class destructor

Base3 class destructor

Leave a Comment

Your email address will not be published. Required fields are marked *

Do NOT follow this link or you will be banned from the site! Scroll to Top