Difference Between Multiple and Multilevel Inheritance
Difference Between Multiple and Multilevel Inheritance
Inheritance
www.differencebetween.com
A B and C are classes. A and B are base classes, and C is the derived class. The class C has
to manage the dependency of both base classes A and B. Multiple inheritances is not
widely used in software projects. It makes the system more complex because one class is
inheriting many classes.
For example, assume that class A and B both have a method with the same name which
is the sum() and class C is deriving both classes. After creating an object of type C and
calling sum () method, it can cause an error because both classes have the same method.
The compiler does not know which function to call. Therefore, Multiple Inheritance
increases the complexity of a system. Multiple Inheritance is supported in C++
language but languages such as Java, C# do not support Multiple Inheritance. Instead,
these languages use interface that is similar to a class but cannot be instantiated.
Multilevel inheritance has three levels. The intermediate class that B inherits from class
A and class C inherits from class B. A is the base class for B and B is the base class for C.
According to the above program, class A is the base class for class B. Class B is the base
class for class C. All properties and methods of class A is accessible by class B. All
properties and methods of class B is accessible by class C. Therefore, class C can access
properties and methods of both A and B. When creating an object of type C, it is possible
to call all three method A (), B () and C (). The output will give A, B, C.
Class Levels
Reference:
Image Courtesy: