Constructors in Multiple Inheritance

Medium Multiple & Virtual Inheritance
Solve in Playground →

Problem Statement

Create base classes `A` and `B`. Their constructors should print ‘A initialized’ and ‘B initialized’ respectively. Create `C` inheriting from `A` then `B`. Its constructor should print ‘C initialized’. In `main()`, instantiate `C` to observe the constructor execution order.

Input Format

None

Output Format

Print the sequence of constructor messages.

Constraints

None

Sample Output

A initialized
B initialized
C initialized

Explanation

Constructors are called in the order the base classes are inherited in the class declaration.

Starter Code

#include <iostream>

class A {
public:
    // Write your constructor here
};

class B {
public:
    // Write your constructor here
};

class C : public A, public B {
public:
    // Write your constructor here
};

int main() {
    // Instantiate C
    return 0;
}

Limits

  • Time Limit: 1s
  • Memory Limit: 256MB

Embedded C Programming

Updated: March 15, 2026
Intermediate

Embedded systems rely on efficient low-level programming to interact directly with hardware. In this course, you will learn how to write practical Embedded C programs used in real microcontroller-based systems. Rather than focusing only on theory, this course follows a practice-driven approach. Each lesson includes hands-on coding exercises that simulate real firmware development tasks used