Question
1.
#include
2.
using namespace std;
3.
class BaseClass
4.
{
5.
protected:
6.
int i;
7.
public:
8.
BaseClass(int x)
9.
{
10.
i = x;
11.
}
12.
~BaseClass()
13.
{
14.
}
15.
};
16.
class DerivedClass: public BaseClass
17.
{
18.
int j;
19.
public:
20.
DerivedClass(int x, int y): BaseClass(y)
21.
{
22.
j = x;
23.
}
24.
~DerivedClass()
25.
{
26.
}
27.
void show()
28.
{
29.
cout
What is the output of this program?
1.
#include
2.
using namespace std;
3.
class BaseClass
4.
{
5.
protected:
6.
int i;
7.
public:
8.
BaseClass(int x)
9.
{
10.
i = x;
11.
}
12.
~BaseClass()
13.
{
14.
}
15.
};
16.
class DerivedClass: public BaseClass
17.
{
18.
int j;
19.
public:
20.
DerivedClass(int x, int y): BaseClass(y)
21.
{
22.
j = x;
23.
}
24.
~DerivedClass()
25.
{
26.
}
27.
void show()
28.
{
29.
cout
Answer: Option B
Was this answer helpful ?
In this program, We are passing the values and assigning it to i and j and we are printing it.
Output:
$ g++ der1.cpp
$ a.out
4 3
Was this answer helpful ?
More Questions on This Topic :
Question 1.
Where is the derived class is derived from?
....
Question 2.
Pick out the correct statement.
....
Submit Solution