Question OOP-INH-0007
EasyWhat is the output of this code?
#include <iostream>
using namespace std;
class Base {
public:
Base() { cout << "Base "; }
};
class Derived : public Base {
public:
Derived() { cout << "Derived"; }
};
int main() {
Derived d;
return 0;
}
- A.
Base
- B.
Base Derived
- C.
Show answer and explanation
Answer: B
Creating a derived object runs the base-class constructor first, then the derived one.