---
title: "Constructor and destructor order, multilevel inheritance"
subject: "Object Oriented Programming"
chapter: 6
key: "semester_3/object_oriented_programming:ctor-order-multilevel"
source: https://www.bctengineer.com/q/semester_3/object_oriented_programming/ctor-order-multilevel
site: BCT Engineering
---

# Constructor and destructor order, multilevel inheritance

Object Oriented Programming · Chapter 6: Inheritance

- Asked in: 2074 Asoj, 5 marks; 2073 Shrawan, 5 marks (asked 2 times)
- Video: [C++ Inheritance: constructors and destructors in base and derived classes  [3]](https://www.youtube.com/watch?v=vuz6ezCN7uM) — Professor Hank Stalica
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_3/object_oriented_programming/ctor-order-multilevel
- Whole chapter: https://www.bctengineer.com/md/semester_3/object_oriented_programming/chapter-6

## Question

Write a program to show the order of constructor (and destructor) invocation in multilevel inheritance. Show your program outputs.

## Short answer

In multilevel inheritance, base class constructors are called first from the topmost in the hierarchy, then derived constructors. Destructors are called in the exact reverse order. For hierarchy A→B→C, creating object of C invokes A, B, C constructors; destruction order is C, B, A.

## Answer

In inheritance, constructors are called in the order of derivation: **base class first, then derived classes** (from the top of the hierarchy downwards). Destructors are called in the **reverse** order. In multilevel inheritance A -> B -> C, creating an object of C calls constructors A, B, C, and destructors C, B, A.

```cpp
#include <iostream>
using namespace std;

class A {
public:
    A()  { cout << "Constructor of A" << endl; }
    ~A() { cout << "Destructor of A" << endl; }
};

class B : public A {
public:
    B()  { cout << "Constructor of B" << endl; }
    ~B() { cout << "Destructor of B" << endl; }
};

class C : public B {
public:
    C()  { cout << "Constructor of C" << endl; }
    ~C() { cout << "Destructor of C" << endl; }
};

int main() {
    cout << "Creating object of C" << endl;
    C obj;
    cout << "End of main" << endl;
    return 0;
}
```

**Output:**

```text
Creating object of C
Constructor of A
Constructor of B
Constructor of C
End of main
Destructor of C
Destructor of B
Destructor of A
```

The derived constructor cannot finish before its base part exists, so the base is built first. Likewise the base part must be destroyed last, so destruction goes in reverse.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. In A -> B -> C multilevel inheritance, creating a C object calls constructors in what order?
   A. C, B, A
   B. B, A, C
   C. A, C, B
   D. A, B, C
   Answer: D. Base first, moving down the hierarchy. (Key point: Constructor order)

2. In what order are destructors called?
   A. C, B, A
   B. A, B, C
   C. B, C, A
   D. Random
   Answer: A. Destruction is the reverse of construction. (Key point: Destructor order)

3. Why is the base built first?
   A. Alphabetical order
   B. The derived part depends on the base part existing
   C. Base constructors are faster
   D. Derived classes have no constructors
   Answer: B. The derived constructor cannot finish before its base part exists. (Key point: Reason)

## Related in Object Oriented Programming

- [Constructor/destructor order; parameterized base constructor](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Actor-dtor-order-single-multiple) — Object Oriented Programming, chapter 6, asked 2×
- [Department class constructor and destructor](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Adept-class-destructor-order) — Object Oriented Programming, chapter 4

## Related in other subjects

- [Program for RK-4 first order IVP](https://www.bctengineer.com/question.md?key=semester_4%2Fnumerical_method%3Ark4-program-first-order) — Numerical Method, chapter 6
- [Program for RK-4 second order IVP](https://www.bctengineer.com/question.md?key=semester_4%2Fnumerical_method%3Ark4-program-second-order) — Numerical Method, chapter 6
