C++ Programming
DERIVED CLASSES MCQs
Total Questions : 10
Because it is having the proper data set to initialize, Otherwise it will throw a error.
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
In this program, We are passing the value and getting the result by derived class.
Output:
$ g++ der5.cpp
$ a.out
10 100
None.
Answer:b
Explanation:In this program, We got an error in overloading because we didn’t invoke the
destructor of parent.
Answer:a
Explanation: In this program, We are printing the execution order of the program.
Output:
$ g++ der2.cpp
$ a.out
Instantiating Base
Base
Instantiating Derived
Base
Derived
None.
In this program, We are passing the value and manipulating by using the derived class.
Output:
$ g++ der.cpp
$ a.out
54.3R
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
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
Because derived inherits functions and variables from base.
Destructors are automatically invoked when a object goes out of scope or when a dynamically
allocated object is deleted. Inheritance does not change this behavior. This is the reason a
derived destructor cannot invoke its base class destructor.
Recent Questions
Q. In Each Question, The First And The Last Sentences Of The Pa....
Q. His Death Is A Great Blow, Most Terrible To . . . . . . . .
Q. Azure Blob Storage Offers How Many Storage Tiers?
Q. Find Out Whether There Is Any Grammatical Error In Below Sen....
Q. In Power Point, This Is A Container For Text Or Graphics.
Q. Symmetric Multiprocessing (SMP) Architectures Are Useful For....
Q. It Is An Instrument That Entitles The Holder To A Proportio....
Q. In Each Question Below A Sentence Broken Into Four Or Five P....
Q. The Playground Of Lawn Tennis Is Called
Q. How Many Numbers (N) Can We Have, Such That 100<N<1000....
Q. a Button That Makes Characters Either Upper Or Lower Case ....
Q. the Area Of A Rectangle Is 45 Cm². If Its Length Is 9 Cm,....
Q. Which Of The Following Presentation Elements Can You Modify ....
Q. Di....
Q. Adversity
Q. 1 U = _______ Nanokatals.
Q. The Manner In Which Bombs Exploded In Five Trains With In A ....
Q. Spiny Seeds With Hooks are Dispersed By Animals.
Q. The Process Of Improving The Cutting Action Of The Grinding ....
Q. To Meet The Educational Needs Of The People, The Madarasa-I ....