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.
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.
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.
Comparison Chart
Basis | Single Inheritance | Multiple 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.
|
Safe | Single inheritance is safer than multiple inheritances | Multiple inheritances are not safe to implement |
Access | In single inheritance features of a single class is inherited | In multiple inheritance features of multiple classes can be inherited |
Runtime | Single inheritance require more run time | Multiple inheritance require less run time |
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.
Key Differences between Single Inheritance and Multiple 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.
- Single inheritance is safer than multiple inheritances whereas multiple inheritances are not safe to implement.
- In single inheritance features of a single class is inherited whereas in multiple inheritance features of multiple classes can be inherited.
- 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