Which one of the following most accurately describes "multiple inheritance"?
2017
Which one of the following most accurately describes "multiple inheritance"?
- A.
When a child class has both an "is-a" and a "has-a" relationship with its parent class.
- B.
When two classes inherit from each other.
- C.
When a base class has two or more derived classes.
- D.
When a child class has two or more parent classes.
Attempted by 358 students.
Show answer & explanation
Correct answer: D
Definition: Multiple inheritance is a feature of some object-oriented programming languages in which a class can inherit features (methods and properties) from more than one parent class. Simple example: If class D inherits from class A and class B, then D receives attributes and behaviors from both A and B.
Language support: Some languages like C++ support multiple inheritance of classes. Other languages like Java and C# do not allow multiple class inheritance and use interfaces or other mechanisms instead.
Diamond problem: If two parent classes inherit from the same grandparent and the child inherits from both parents, there can be ambiguity about which grandparent implementation to use. Languages provide different solutions (for example, virtual inheritance in C++ or using interfaces).
A video solution is available for this question — log in and enroll to watch it.