Object Oriented Programming using C++ Questions and Answers – Multilevel Inheritance

This set of Object Oriented Programming (OOPs) using C++ Multiple Choice Questions & Answers (MCQs) focuses on “Multilevel Inheritance”.

1. Which among the following best defines multilevel inheritance?
a) A class derived from another derived class
b) Classes being derived from other derived classes
c) Continuing single level inheritance
d) Class which have more than one parent
View Answer

Answer: b
Explanation: Only if the class is being derived from other derived class, it can be called as multilevel inheritance. If a class is derived from another class, it is single level inheritance. There must be more than one level of inheritance.

2. If there are 5 classes, E is derived from D, D from C, C from B and B from A. Which class constructor will be called first if the object of E or D is created?
a) A
b) B
c) C
d) A and B
View Answer

Answer: a
Explanation: A is parent of all other classes indirectly. Since A is parent of B and B is parent of C and so on till E. Class A constructor will be called first always.

3. If there are 3 classes. Class C is derived from class B and B is derived from A, Which class destructor will be called at last if object of C is destroyed.
a) A
b) B
c) C
d) All together
View Answer

Answer: a
Explanation: The destructors are called in the reverse order of the constructors being called. Hence in multilevel inheritance, the constructors are created from parent to child, which leads to destruction from child to parent. Hence class A destructor will be called at last.
advertisement
advertisement

4. Which Class is having highest degree of abstraction in multilevel inheritance of 5 levels?
a) Class at 1st level
b) Class 2nd last level
c) Class at 5th level
d) All with same abstraction
View Answer

Answer: a
Explanation: The class with highest degree of abstraction will be the class at the 1st level. You can look at a simple example like, a CAR is more abstract than SPORTS CAR class. The level of abstraction decrease with each level as more details comes out.

5. If all the classes use private inheritance in multilevel inheritance then ______________
a) It will not be called multilevel inheritance
b) Each class can access only non-private members of its parent
c) Each subsequent class can access all members of previous level parent classes
d) None of the members will be available to any other class
View Answer

Answer: b
Explanation: The classes will be able to access only the non-private members of its parent class. The classes are using private inheritance, hence all the members of the parent class become private in the derived class. In turn those won’t be allowed for further inheritance or direct access outside the class.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

6. Multilevel inheritance allows _________________ in the program.
a) Only 7 levels of inheritance
b) At least 7 levels of inheritance
c) At most 16 levels of inheritance
d) As many levels of inheritance as required
View Answer

Answer: d
Explanation: The multilevel inheritance allows any number of levels of inheritance. This is the maximum flexibility feature to make the members available to all the new classes and to add their own functionalities. The code reusability is used too.

7. What is the minimum number of levels for a implementing multilevel inheritance?
a) 1
b) 2
c) 3
d) 4
View Answer

Answer: c
Explanation: There must be at least 3 levels of inheritance. Otherwise if less, it will be single level inheritance or would have got no inheritance implemented. There must be a derived class from which another class is derived.
advertisement

8. In multilevel inheritance one class inherits _______________
a) Only one class
b) More than one class
c) At least one class
d) As many classes as required
View Answer

Answer: a
Explanation: The classes inherit only from one class. This continues as each class inherits only one class. There should not be any class that inherits from two or more classes or which have more than one subclass.

9. All the classes must have all the members declared private to implement multilevel inheritance.
a) True
b) False
View Answer

Answer: b
Explanation: There is no mandatory rule to make the members private for multilevel inheritance. Moreover, if all the classes have only the private members then there won’t be any member to get inherited. Hence the working will be of no use.
advertisement

10. Can abstract classes be used in multilevel inheritance?
a) Yes, always
b) Yes, only one abstract class
c) No, abstract class doesn’t have constructors
d) No, never
View Answer

Answer: a
Explanation: The abstract classes can always be used in multilevel inheritance. The only condition that may arise is that all the undefined functions must be defined in subclasses. There must not be any undefined function.

11. How many abstract classes can be used in multilevel inheritance?
a) Only 1
b) Only 2
c) At least one less than number of levels
d) Can’t be used
View Answer

Answer: c
Explanation: At least one class must implement all the undefined functions. Hence there must be at least one class which is not abstract. That is at least one less than number of levels.

12. If all the classes used parameterized constructors and no default constructor then ___________
a) The object of lower level classes can’t be created
b) Object of lower level classes must call parent class constructors explicitly
c) Object of lower level classes must define all the default constructors
d) Only object of first class can be created, which is first parent
View Answer

Answer: b
Explanation: Each class constructor must be called before creating the object of any subclass. Hence it will be mandatory to call the constructors of parent classes explicitly with parameters. This will make all the previous class member be initialized and then the class in use will be able to create the object.

13. In multilevel inheritance, which is the most significant feature of OOP used?
a) Code readability
b) Flexibility
c) Code reusability
d) Code efficiency
View Answer

Answer: c
Explanation: The classes using multilevel inheritance will use the code in all the subsequent subclasses if available. Hence the most significant feature among the options given is code reusability. This feature is generally intended to use the data values and reuse the redundant functions.

14. Does following code show multiple inheritance?

 
class A
{
	int a;
};
class B
{
	int b;
};
class C:public A, public B
{
	int c;
};
class D:public C
{
	int d;
};

a) Yes, class C and class D
b) Yes, All together it’s multilevel
c) No, 4 classes are used
d) No, multiple inheritance is used with class A, B and C
View Answer

Answer: d
Explanation: Since multiple inheritance is used to derive class C and then class D is derived from class C. This is not multilevel inheritance. The classes should derive from single class. This is actually hybrid inheritance.

15. Is it compulsory for all the classes in multilevel inheritance to have constructors defined explicitly if only last derived class object is created?
a) Yes, always
b) Yes, to initialize the members
c) No, it not necessary
d) No, Constructor must not be defined
View Answer

Answer: c
Explanation: It’s not mandatory to define the constructors explicitly. Default constructor will always be provided by the compiler itself if none another constructor is defined in those classes. If explicit default constructor is defined it will be used.

Sanfoundry Global Education & Learning Series – Object Oriented Programming (OOPs).

To practice all areas of Object Oriented Programming (OOPs) using C++, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.