-
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;
}
-
- 250
150 - 350
- 250
- 150
250 - None of these
- 250
Correct Option: D
In this program, We are passing the values by using multiple inheritance and printing the derived values.