The main difference between single and multiple inheritance is that in single inheritance, the subclass inherits properties and methods from a single superclass while in multiple inheritance, the subclass inherits properties and methods from multiple superclasses.
Object-oriented programming (OOP) is a common software paradigm used in enterprise-level software development. It allows developing the software using objects. Moreover, an object is an entity that has states and behaviors. A class is used to create an object. Therefore, a class is a blueprint. The properties or attributes represent the states of an object. Furthermore, the methods of an object represent the behaviors of an object. One major concept in OOP is inheritance. It is the methodology of allowing properties and methods of an existing class in a new class. Additionally, this enables code reusability and adding new features to the existing code. Single and multiple inheritance are two types of inheritance.
Key Areas Covered
1. What is Single Inheritance
– Definition, Functionality
2. What is Multiple Inheritance
– Definition, Functionality
3. Difference Between Single and Multiple Inheritance
– Comparison of Key Differences
Key Terms
Class, Inheritance, Multiple Inheritance, Object, Single Inheritance,
What is Single Inheritance
In inheritance, the existing class is called the parent class, superclass or the base class. The new class called the child class, subclass or derived class. Using inheritance, the subclass can use the properties and methods of the superclass. Thus, programmers do not have to implement the whole program from the beginning. Single inheritance is the simplest form of inheritance.
A and B are two classes. Class B inherits class A. Therefore, Class B is the subclass and class A is the superclass. Thus, class B can use the properties and methods of class A. Thus, this kind of inheritance is called single inheritance. As there is only one level, it is also called single level inheritance.
What is Multiple Inheritance
In multiple inheritance, the new class can use the properties and methods of multiple classes. Programmer can implement multiple inheritance in languages such as C++. However, languages such as Java and C# does not support multiple inheritance. Instead, these languages use interfaces to implement multiple inheritance.
Let’s now look at an example to understand the concept of multiple inheritance more clearly. A, B and C are three classes. Class C inherits from both A and B classes. Therefore, class C can inherit properties and methods of both class A and B.
Difference Between Single and Multiple Inheritance
Definition
Single inheritance is a type of inheritance that enables a derived class to inherit attributes and methods from a single parent class while multiple inheritance is a type of inheritance that enables a derived class to inherit attributes and methods from more than one parent class. Thus, this is the main difference between single and multiple inheritance.
Functionality
In single inheritance, a subclass inherits from a single superclass whereas, in multiple inheritance, a subclass inherits from multiple superclasses. Hence, this is another difference between single and multiple inheritance.
Programming languages
Moreover, programmers can implement single inheritance using any programming language that supports OOP. In contrast, C++ language supports multiple inheritance while languages such as Java, C# do not support multiple inheritance.
Complexity
Complexity is also a difference between single and multiple inheritance. Multiple inheritance is more complex than single multiple inheritance.
Conclusion
Inheritance is the OOP methodology of creating a new class from an existing class. It makes the code more elegant and less repetitive. Moreover, there are various types of inheritance, and single and multiple inheritance are two of them. In brief, the main difference between single and multiple inheritance is that, in single inheritance, the subclass inherits properties and methods from a single superclass while in multiple inheritance, the subclass inherits properties and methods from multiple superclasses.
References:
1.”Inheritance in Java.” Www.javatpoint.com, Available here.
2.”What is Single Inheritance? – Definition from Techopedia.” Techopedia.com, Available here.
Image Courtesy:
1.”Single inheritance” By Author: Suman Maverick Gangulian Suman420 (talk) 08:49, 2 March 2015 (UTC) – Own work (CC BY 3.0) via Commons Wikimedia
2.”Multiple inheritance” By Suman Maverick Gangulian Suman420 – Own work (CC BY 3.0) via Commons Wikimedia
Leave a Reply