0% found this document useful (0 votes)
75 views

Difference Between Multiple and Multilevel Inheritance

Uploaded by

SRUJAN KALYAN
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
75 views

Difference Between Multiple and Multilevel Inheritance

Uploaded by

SRUJAN KALYAN
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Difference Between Multiple and Multilevel

Inheritance
www.differencebetween.com

Key Difference - Multiple vs Multilevel Inheritance


Object-Oriented Programming (OOP) is a paradigm to design a program using classes
and methods. Real world scenarios can be mapped to objects. Therefore, it is easy to
build software solutions. A class is a blueprint to build an object. It contains properties
and methods. For example, before creating a student object, there should be a class
student with properties and methods. A student can have properties such as student id,
name and methods such as read, write, study. Methods describe the behaviour while
properties are the attributes. After creating the class, it is possible to create objects using
them. Object creation is also known as Object Instantiation. Object does not exist in
isolation. They communicate with other objects and data is passed within objects. One
pillar of OOP is Inheritance. The purpose of Inheritance is to increase code reusability. It
creates a new class of properties and methods of the already existing class. The existing
class is known as the base class, and the new class is called the derived class. Multiple
Inheritance and Multilevel Inheritance are inheritance types. This article discusses the
difference between them. The key difference between Multiple and Multilevel
Inheritance is that Multiple Inheritance is when a class inherits from many base
classes while Multilevel Inheritance is when a class inherits from a derived
class making that derived class a base class for a new class.

What is Multiple Inheritance?


Multiple Inheritance is when a class inherits more than one base class.
Figure 01: Multiple Inheritance

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.

What is Multilevel Inheritance?


Multilevel Inheritance is when a class inherits from a derived class making that derived
class a base class for a new class.
Figure 02: Multilevel Inheritance

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.

A program that implements Multilevel Inheritance is as follows. The program is written


using Java.
Figure 03: Program that implements Multilevel Inheritance

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.

What is the Similarity Between Multiple and


Multilevel Inheritance?
 Both are types of Inheritance.

What is the Difference Between Multiple and


Multilevel Inheritance?
Multiple Inheritance vs Multilevel Inheritance
Multiple Inheritance is an Inheritance Multilevel Inheritance is an Inheritance type that
type where a class inherits from more inherits from a derived class, making that derived
than one base class. class a base class for a new class.
Usage

Multiple Inheritance is not widely used


because it makes the system more Multilevel Inheritance is widely used.
complex.

Class Levels

Multiple Inheritance has two class


Multilevel Inheritance has three class levels namely,
levels namely, base class and derived
base class, intermediate class and derived class.
class.

Summary - Multiple vs Multilevel Inheritance


Inheritance is a major pillar of Object Oriented Programming. There are types of
Inheritance. They are Single Level Inheritance, Multilevel Inheritance, Multiple
Inheritance, Hierarchical Inheritance and Hybrid Inheritance. The Single Level
Inheritance has one base class and one derived class. Hierarchical Inheritance has one
base class and many derived classes. The Hybrid Inheritance is a combination of
Multilevel and Multiple Inheritance. This article described the difference between
Multiple Inheritance and Multilevel Inheritance. The difference between Multiple and
Multilevel inheritances is that Multiple Inheritance is when a class inherits from many
base classes while Multilevel is when a class inherits from a derived class, making that
derived class a base class for a new class. Multilevel Inheritance is widely used than
Multiple Inheritance.

Reference:

1.Singh, Chaitanya, et al. “Types of inheritance in Java: Single,Multiple,Multilevel &


Hybrid.” Beginnersbook.com, 6 Dec. 2013. Available here
2.tutorialspoint.com. “Java Inheritance.” The Point. Available here

Image Courtesy:

1.'Multiple Inheritance'By Suman Maverick Gangulian Suman420 - Own work, (CC BY


3.0) via Commons Wikimedia
2.'Multilevel Inheritance'By Author: Suman Maverick Gangulian Suman420 (talk)
12:03, 2 March 2015 (UTC) - Own work, (CC BY 3.0) via Commons Wikimedia

How to Cite this Article?

APA: Difference Between Multiple and Multilevel Inheritance.(2018 January 22).


Retrieved (date), from http://differencebetween.com/difference-between-multiple-and-
vs-multilevel-inheritance/
MLA: "Difference Between Multiple and Multilevel Inheritance" Difference
Between.Com. 22 January 2018. Web.

Chicago: “Difference Between Multiple and Multilevel Inheritance.” Difference


Between.Com. http://differencebetween.com/difference-between-multiple-and-vs-
multilevel-inheritance/ accessed (accessed [date]).

Copyright © 2010-2017 Difference Between. All rights reserved

You might also like