CJCoding With Joseph
15per day

Constructor and Destructor Order

A base class Base has been provided with a constructor that prints "Base constructor" and a virtual destructor that prints "Base destructor".

A derived class Derived publicly inherits from Base.

Your task is to implement:
1. The Derived constructor - it should print "Derived constructor"
2. The Derived destructor - it should print "Derived destructor"

When a Derived object is created, the Base constructor runs first, then Derived. When destroyed, Derived destructor runs first, then Base.

Do NOT include a main function. Your code will be tested automatically.

Expected output:
Base constructor
Derived constructor
Derived destructor
Base destructor

Expected Output:

Base constructor
Derived constructor
Derived destructor
Base destructor
Topics:
Inheritance
Code Editor
1
Tab to indent ยท Ctrl+Enter to run ยท Ctrl+Space to expand shortcuts (cout, fori)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.