Single Inheritance vs. Multiple Inheritance

The key difference between single inheritance and multiple inheritances is that in single inheritance, the derived class inherits only a single base class whereas, in multiple inheritances, the derived class inherits more than one base class.

Advertisement - Continue Reading Below
Single Inheritance vs. Multiple Inheritance

Inheritance is one of the most important concepts in OOP that is object oriented programming. Concept of reusability is supported in inheritance. Reusability means new class reuses the properties of the already existing class. In inheritance derived class inherit the base class and access, specifier decides which base class member will be inherited. There are types of inheritance that are a single inheritance, hierarchical inheritance, multilevel inheritance and hybrid inheritance. In single inheritance, the derived class inherits only a single base class whereas, in multiple inheritances, the derived class inherits more than one base class.

There is a just a single derived class that is inherited from the base class. There are three ways to inherit the base class that is public, protected and privately. Access specifier is used to inheriting the base class.  The reason for single inheritance is to inherit the properties and behavior from a single parent class. The main purpose of object oriented programming that is code reusability is fulfilled by using single inheritance. If we talk single inheritance as compare to multiple inheritance than, single inheritance is must more easily as compared to multiple inheritance. Function overriding is used in single inheritance. Run-time polymorphism is known as overriding. Overriding is achieved by using a function keyword that is virtual. This keyword is use in base class. When derived class redefine a function, overridden function cannot be changed. Overriding in C++ determines that which version of the function is called. Single inheritance is used in C++, Java, PHP, C# and visual basis.

Advertisement - Continue Reading Below

Multiple inheritance allow to derive more than one base class it mean you can get the properties of more than one base class. We can have one derived class and multiple base classes. Base class is inherited by mentioning the separate access specifier. Multiple inheritance have symmetrical merging and asymmetric extension. When there is adapter pattern multiple inheritance is used. Multiple inheritance is used in C++, Python, Perl, Eiffel, Dylan, Curl, Eulisp, Tcl. The implementation of code for multiple inheritances is complex as compared to single inheritance.

Contents: Difference between Single Inheritance and Multiple Inheritance

Comparison Chart

BasisSingle InheritanceMultiple Inheritance
Meaning In single inheritance, the derived class inherits only a single base class

In multiple inheritances, the derived class inherits more than one base class.

 

SafeSingle inheritance is safer than multiple inheritancesMultiple inheritances are not safe to implement
AccessIn single inheritance features of a single class is inheritedIn multiple inheritance features of multiple classes can be inherited
Runtime Single inheritance require more run timeMultiple inheritance require less run time
Advertisement - Continue Reading Below

 Single Inheritance

There is a just a single derived class that is inherited from the base class. There are three ways to inherit the base class that is public, protected and privately. Access specifier is used to inheriting the base class.  The reason for single inheritance is to inherit the properties and behavior from a single parent class. The main purpose of object oriented programming that is code reusability is fulfilled by using single inheritance. If we talk single inheritance as compared to multiple inheritances than, single inheritance is must more easily as compared to multiple inheritances. Function overriding is used in single inheritance. Run-time polymorphism is known as overriding. Overriding is achieved by using a function keyword that is virtual. This keyword is used in base class. When derived class redefine a function, the overridden function cannot be changed. Overriding in C++ determines that which version of the function is called. Single inheritance is used in C++, Java, PHP, C# and visual basis.

Multiple Inheritance

Multiple inheritances allow deriving more than one base class it means you can get the properties of more than one base class. We can have one derived class and multiple base classes. The base class is inherited by mentioning the separate access specifier. Multiple inheritances have symmetrical merging and asymmetric extension. When there is an adapter pattern, multiple inheritances is used. Multiple inheritances are used in C++, Python, Perl, Eiffel, Dylan, Curl, Eulisp, Tcl. The implementation of code for multiple inheritances is complex as compared to single inheritance.

Advertisement - Continue Reading Below

Key Differences

  1. In single inheritance, the derived class inherits only a single base class whereas, in multiple inheritances, the derived class inherits more than one base class.
  2. Single inheritance is safer than multiple inheritances whereas multiple inheritances are not safe to implement.
  3. In single inheritance features of a single class is inherited whereas in multiple inheritance features of multiple classes can be inherited.
  4. Single inheritance require more run time whereas Multiple inheritances require less run time

Conclusion

In this article above we see the clear difference between single inheritance and multiple inheritances with the implementation

Explanatory Video

Leave a Comment