C++ Programming Multiple Choice Questions - Inheritance
This section focuses on the "Inheritance" in C++ programming langauge. These Multiple Choice Questions (MCQ) should be practiced to improve the C++ programming skills required for various interviews (campus interview, walk-in interview, company interview), placement, entrance exam and other competitive examinations.
1. When the inheritance is private, the private methods in base class are __________ in the derived class (in C++).
View Answer
2. Which design patterns benefit from the multiple inheritances?
View Answer
3. What is meant by multiple inheritance?
View Answer
4. What will be the order of execution of base class constructors in the following method of inheritance.class a: public b, public c {...};
View Answer
5. Inheritance allow in C++ Program?
View Answer
6. Can we pass parameters to base class constructor though derived class or derived class constructor?
View Answer
7. What are the things are inherited from the base class?
View Answer
8. Which of the following advantages we lose by using multiple inheritance?
View Answer
9. What is the output of this program?
Note:Includes all required header files
using namespace std;
class Base
{
public:
Base(){}
~Base(){}
protected:
private:
};
class Derived:public Base
{
public:
Derived(){}
Derived(){}
private:
protected:
};
int main()
{
cout << "Executed" << endl;
}
View Answer
10. What is the output of this program?
Note:Includes all required header files
using namespace std;
int main()
{
string s = "a long string";
s.insert(s.size() / 2, " * ");
cout << s << endl;
return 0;
}
View Answer
11. What is the output of this program?
Note:Includes all required header files
using namespace std;
struct a
{
int p;
};
struct b
{
int* x;
};
struct c : public a, public b
{
};
int main()
{
c* p = new c;
p->x = 0;
cout << "Inherited";
return 0;
}
View Answer
12. What is the output of this program?
Note:Includes all required header files
using namespace std;
class Base1 {
public:
Base1()
{ cout << " Base1" << endl; }
};
class Base2 {
public:
Base2()
{ cout << "Base2" << endl; }
};
class Derived: public Base1, public Base2 {
public:
Derived()
{ cout << "Derived" << endl; }
};
int main()
{
Derived d;
return 0;
}
View Answer
13. Which of the following is true about the following program
Note:Includes all required header files
using namespace std;
class Base1 {
public:
~Base1() { cout << " Base1" << endl; }
};
class Base2 {
public:
~Base2() { cout << " Base2" << endl; }
};
class Derived: public Base1, public Base2 {
public:
~Derived() { cout << " Derived" << endl; }
};
int main()
{
Derived d;
return 0;
}
View Answer
14. Assume that an integer takes 2 bytes and there is no alignment in following classes, predict the output.
Note:Includes all required header files
using namespace std;
class base {
int arr[15];
};
class b1: public base { };
class b2: public base { };
class derived: public b1, public b2 {};
int main(void)
{
cout << sizeof(derived);
return 0;
}
View Answer
15. What will be the output of this program?
#include <iostream>
using namespace std;
class Base {};
class Derived: public Base {};
int main()
{
Base *p = new Derived;
Derived *q = new Base;
}
View Answer
16. What will be the output of the following program?
#include <iostream>
using namespace std;
class Base
{
public:
int lfc() { cout << "Base::lfc() called"; }
int lfc(int i) { cout << "Base::lfc(int i) called"; }
};
class Derived: public Base
{
public:
int lfc() { cout << "Derived::lfc() called"; }
};
int main()
{
Derived d;
d.lfc(5);
return 0;
}
View Answer
17. State whether the following statements about inheritance are True or False.
i) A public member of a class can be accessed by its own objects using the dot operator.
ii) While inheriting, the private members of the base class will never become the members of its derived class.
View Answer
18. In inheritance, order of execution of base class and derived class destructors are:
View Answer
19. What is the difference between protected and private access specifiers in inheritance?
View Answer
20. Which value is placed in the base class?
View Answer
21. The friend functions and the member functions of a friend class can directly access the______________ data.
View Answer
22. What will be the order of execution of base class constructors in the following method of inheritance. class a: public b, virtual public c {...};
View Answer
23. class X, class Y and class Z are derived from class BASE. This is ______ inheritance.
View Answer
24. Reusability of the code can be achieved in CPP through ______ .
View Answer
25. What will be the output of the following program?
Note:Includes all required header files
class find {
public:
void print() { cout <<" In find"; }
};
class course : public find {
public:
void print() { cout <<" In course"; }
};
class tech: public course { };
int main(void)
{
tech t;
t.print();
return 0;
}
View Answer
26. Which symbol is used to create multiple inheritance?
View Answer
27. ___________ inheritance may lead to duplication of inherited members from a "grandparent" base class.
View Answer
28. C++ Inheritance relationship is?
View Answer
29. Private members of the class are not inheritable.
View Answer
Also check :
Discussion