Sail E0 Webinar
Question


What is the output of this program?


1.
#include
2.
using namespace std;
3.
class Base1
4.
{
5.
protected:
6.
int SampleDataOne;
7.
public:
8.
Base1()
9.
{
10.
SampleDataOne = 100;
11.
}
12.
~Base1()
13.
{
14.
}
15.
int SampleFunctOne()
16.
{
17.
return SampleDataOne;
18.
}
19.
};
20.
class Base2
21.
{
22.
protected:
23.
int SampleDataTwo;
24.
public:
25.
Base2()
26.
{
27.
SampleDataTwo = 200;
28.
}
29.
~Base2()
30.
{
31.
}
32.
int SampleFunctTwo()
33.
{
34.
return SampleDataTwo;
35.
}
36.
};
37.
class Derived1 : public Base1, public Base2
38.
{
39.
int MyData;
40.
public:
41.
Derived1()
42.
{
43.
MyData = 300;
44.
}
45.
~Derived1()
46.
{
47.
}
48.
int MyFunct()
49.
{
50.
return (MyData + SampleDataOne + SampleDataTwo);
51.
}
52.
};
53.
int main()
54.
{
55.
Base1 SampleObjOne;
56.
Base2 SampleObjTwo;
57.
Derived1 SampleObjThree;
58.
cout
Options:
A .  100
B .  200
C .  Both a & b
D .  None of the mentioned
Answer: Option C

In this program, We are passing the values by using multiple inheritance and printing the derived values.
Output:
$ g++ mul4.cpp
$ a.out
100
200



Was this answer helpful ?
Next Question

Submit Solution

Your email address will not be published. Required fields are marked *

Latest Videos

Latest Test Papers