---
title: "Constructor/destructor order; parameterized base constructor"
subject: "Object Oriented Programming"
chapter: 6
key: "semester_3/object_oriented_programming:ctor-dtor-order-single-multiple"
source: https://www.bctengineer.com/q/semester_3/object_oriented_programming/ctor-dtor-order-single-multiple
site: BCT Engineering
---

# Constructor/destructor order; parameterized base constructor

Object Oriented Programming · Chapter 6: Inheritance

- Asked in: 2070 Asar, 4 marks; 2068 Chaitra, 5 marks (asked 2 times)
- Video: [Constructors in Derived Classes in C++](https://www.youtube.com/watch?v=zsYuswljFws) — Sudhakar Atchala
- 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-dtor-order-single-multiple
- Whole chapter: https://www.bctengineer.com/md/semester_3/object_oriented_programming/chapter-6

## Question

Explain the constructor and destructor invocation order in single and multiple inheritance. Also show how a parameterized base class constructor is called when derived class object is created.

## Short answer

In single inheritance, base constructor runs before derived; destructors reverse. In multiple inheritance, base constructors execute in the order they are listed in the derived class declaration, then derived. Destructors run in reverse. A parameterized base constructor is called using the member initializer list, e.g., Derived(int x) : Base(x).

## Answer

#### Single inheritance
Base class constructor runs first, then the derived class constructor. Destructors run in reverse: derived first, then base.

#### Multiple inheritance
Base class constructors are called in the order in which the bases are **listed in the derived class declaration** (not the order in the initializer list), then the derived constructor. Destructors run in the exact reverse order.

```cpp
class D : public A, public B { ... };   // order: A(), B(), D()
                                        // destructors: ~D(), ~B(), ~A()
```

#### Passing arguments to a parameterized base constructor
The derived constructor passes values to the base constructor using a **member initializer list** after a colon. If the base class has no default constructor, this is compulsory.

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

class A {
    int a;
public:
    A(int x) { a = x; cout << "A(" << a << ")" << endl; }
    ~A()     { cout << "~A" << endl; }
};

class B {
    int b;
public:
    B(int y) { b = y; cout << "B(" << b << ")" << endl; }
    ~B()     { cout << "~B" << endl; }
};

class D : public A, public B {
    int d;
public:
    // arguments for bases are passed in the initializer list
    D(int x, int y, int z) : B(y), A(x) {
        d = z;
        cout << "D(" << d << ")" << endl;
    }
    ~D() { cout << "~D" << endl; }
};

int main() {
    D obj(1, 2, 3);
    return 0;
}
```

**Output:**

```text
A(1)
B(2)
D(3)
~D
~B
~A
```

Although `B(y)` is written before `A(x)` in the initializer list, `A` is constructed first because `A` is listed first in `class D : public A, public B`.

## Check yourself

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

1. In class D : public A, public B, what decides the order in which base constructors run?
   A. The order in the initializer list
   B. Alphabetical order
   C. The order of the bases in the class declaration
   D. Size of the classes
   Answer: C. Bases are constructed in declaration order, regardless of the initializer list. (Key point: Multiple inheritance order)

2. How does a derived constructor pass arguments to a parameterized base constructor?
   A. Using a member initializer list after a colon
   B. Calling the base constructor in the body
   C. Using virtual
   D. Using friend
   Answer: A. The initializer list, e.g. D(...) : A(x), B(y), supplies base arguments. (Key point: Parameterized base)

3. For D(1,2,3) with initializer list B(y), A(x), what is the construction output order?
   A. B(2), A(1), D(3)
   B. D(3), A(1), B(2)
   C. A(1), D(3), B(2)
   D. A(1), B(2), D(3)
   Answer: D. A is listed first in the class declaration, so A is built first. (Key point: Output)

4. What is the destructor order for D?
   A. ~A, ~B, ~D
   B. ~D, ~B, ~A
   C. ~D, ~A, ~B
   D. ~B, ~A, ~D
   Answer: B. Destructors run in exact reverse order of construction. (Key point: Destructors)

## Related in Object Oriented Programming

- [Constructor and destructor order, multilevel inheritance](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Actor-order-multilevel) — 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
- [Access overridden members from derived class](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Aaccess-overridden-members) — Object Oriented Programming, chapter 6, asked 2×
- [Ambiguity in multiple inheritance](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Aambiguity-multiple-inheritance) — Object Oriented Programming, chapter 6

## Related in other subjects

- [Object adapter and CORBA invocation](https://www.bctengineer.com/question.md?key=semester_7%2Fdistributed_system%3Aobject-adapter-invocation) — Distributed System, chapter 4
