Home » C++ Programming » Inheritance » Question
  1. What is the output of this program?
    #include <iostream>
    using namespace std;
    class BaseClassA
    {
    protected:
    int FirstData;
    public:
    BaseClassA()
    {
    FirstData = 150;
    }
    ~BaseClassA()
    {
    }
    int FirstFunction()
    {
    return FirstData;
    }
    };
    class BaseClassB
    {
    protected:
    int SecondData;
    public:
    BaseClassB()
    {
    SecondData = 250;
    }
    ~BaseClassB()
    {
    }
    int SecondFunction()
    {
    return SecondData;
    }
    };
    class DerivedClass : public BaseClassA, public BaseClassB
    {
    int ThirdData;
    public:
    DerivedClass()
    {
    ThirdData = 350;
    }
    ~DerivedClass()
    {
    }
    int Function()
    {
    return (ThirdData + FirstData + SecondData);
    }
    };
    int main()
    {
    BaseClassA FirstObject;
    BaseClassB SecondObject;
    DerivedClass ThirdObject;
    cout << ThirdObject.BaseClassA :: FirstFunction() << endl;
    cout << ThirdObject.BaseClassB :: SecondFunction() << endl;
    return 0;
    }
    1. 250
      150
    2. 350
    3. 250
    4. 150
      250
    5. None of these
Correct Option: D

In this program, We are passing the values by using multiple inheritance and printing the derived values.



Your comments will be displayed only after manual approval.