← Back to Inheritance
Question 131
Constructor and Destructor Order
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
= newline. The output ends with a newline — print one after the last line.
Hints4 available
Sign in to use hintsTopics:
Inheritance
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · 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.