-
What is the output of this program?
#include <iostream>
using namespace std;
class BaseClass
{
public:
int x;
BaseClass(int num=0)
: x(num)
{
cout << "Base" << endl;
}
};
class DerivedClass: public BaseClass
{
public:
double y;
DerivedClass(double d = 0.0)
: y(d)
{
cout <<"Derived" << endl;
}
};
int main()
{
cout << "Instantiating Base" << endl;
BaseClass cBase;
cout << "Instantiating Derived" << endl;
DerivedClass cDerived;
return 0;
}
-
- Instantiating Base
Base - Instantiating Derived
Base
Derived - Instantiating Derived
Derived - Instantiating Base
Base
Instantiating Derived
Base
Derived - None of these
- Instantiating Base
Correct Option: D
In this program, We are printing the execution order of the program.