Question
1.
#include
2.
using namespace std;
3.
class X
4.
{
5.
int m;
6.
public:
7.
X() : m(10)
8.
{
9.
}
10.
X(int mm): m(mm)
11.
{
12.
}
13.
int getm()
14.
{
15.
return m;
16.
}
17.
};
18.
class Y : public X
19.
{
20.
int n;
21.
public:
22.
Y(int nn) : n(nn) {}
23.
int getn() { return n; }
24.
};
25.
int main()
26.
{
27.
Y yobj( 100 );
28.
cout
What is the output of this program?
1.
#include
2.
using namespace std;
3.
class X
4.
{
5.
int m;
6.
public:
7.
X() : m(10)
8.
{
9.
}
10.
X(int mm): m(mm)
11.
{
12.
}
13.
int getm()
14.
{
15.
return m;
16.
}
17.
};
18.
class Y : public X
19.
{
20.
int n;
21.
public:
22.
Y(int nn) : n(nn) {}
23.
int getn() { return n; }
24.
};
25.
int main()
26.
{
27.
Y yobj( 100 );
28.
cout
Answer: Option A
Was this answer helpful ?
In this program, We are passing the value and getting the result by derived class.
Output:
$ g++ der5.cpp
$ a.out
10 100
Was this answer helpful ?
More Questions on This Topic :
Question 7.
Where is the derived class is derived from?
....
Question 8.
Pick out the correct statement.
....
Submit Solution