Home » C++ Programming » Classes & Objects » Question
  1. 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;
    }
    1. Instantiating Base
      Base
    2. Instantiating Derived
      Base
      Derived
    3. Instantiating Derived
      Derived
    4. Instantiating Base
      Base
      Instantiating Derived
      Base
      Derived
    5. None of these
Correct Option: D

In this program, We are printing the execution order of the program.



Your comments will be displayed only after manual approval.