What is the Difference Between Multiple and Multilevel Inheritance?

🆚 Go to Comparative Table 🆚

The main difference between multiple and multilevel inheritance lies in the number of base classes inherited and the structure of the inheritance hierarchy.

  • Multiple Inheritance: In this type of inheritance, a single class inherits properties and behavior from more than one base class. Multiple inheritance is not widely used because it can make the system more complex. Inheritance levels in multiple inheritance are limited to two: the base class and the derived class.
  • Multilevel Inheritance: In multilevel inheritance, a class inherits from a derived class that itself inherits from another base class. This creates a chain of inheritance, with the derived class acting as an intermediate class for the third class. Multilevel inheritance is widely used because it allows for more complex and organized inheritance structures. Inheritance levels in multilevel inheritance consist of the base class, the intermediate class, and the derived class.

In summary, multiple inheritance involves a single class inheriting from multiple base classes directly, while multilevel inheritance involves a class inheriting from another derived class, which in turn inherits from a base class.

Comparative Table: Multiple vs Multilevel Inheritance

Here is a table comparing Multiple Inheritance and Multilevel Inheritance:

Feature Multiple Inheritance Multilevel Inheritance
Definition A class inherits from more than one base class. A class is derived from a base class that itself is derived from yet another base class.
Usage Not widely used, as it makes the system more complex. Widely used.
Class Levels Two class levels: base class and derived class. Three class levels: base class, intermediate class, and derived class.
Overriding Methods Less control over overriding methods. More control over overriding methods, less likely to make mistakes.

Multiple Inheritance is when a class inherits from several base classes, which can lead to complexity and potential conflicts in the system. In contrast, Multilevel Inheritance involves a class being derived from a base class that is itself derived from another base class, providing more control over method overriding and reducing the likelihood of mistakes.