Home » C++ Programming » Classes & Objects » Question
  1. What is the output of this program?
    #include <iostream>
    using namespace std;
    class FirstClass
    {
    int m;
    public:
    FirstClass() : m(12)
    {
    }
    FirstClass(int mm): m(mm)
    {
    }
    int getm()
    {
    return m;
    }
    };
    class SecondClass : public FirstClass
    {
    int n;
    public:
    SecondClass(int nn) : n(nn) {}
    int getn() { return n; }
    };
    int main()
    {
    SecondClass object(105);
    cout << object.getm() << " " << object.getn() << endl;
    }
    1. 12
    2. 105
    3. 105 12
    4. 12 105
    5. None of these
Correct Option: D

In this program, We are passing the value and getting the result by derived class.



Your comments will be displayed only after manual approval.