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

Write Different Types of Inheritance Explain With Diagram?

This document discusses different types of inheritance in object-oriented programming: 1) Single inheritance allows a class to inherit from one parent class. 2) Multiple inheritance allows a class to inherit from more than one parent class, but Java does not support this due to complexity. 3) Other inheritance types discussed include multilevel, hierarchical, and hybrid inheritance.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
99 views

Write Different Types of Inheritance Explain With Diagram?

This document discusses different types of inheritance in object-oriented programming: 1) Single inheritance allows a class to inherit from one parent class. 2) Multiple inheritance allows a class to inherit from more than one parent class, but Java does not support this due to complexity. 3) Other inheritance types discussed include multilevel, hierarchical, and hybrid inheritance.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

1.

Write different Types of Inheritance Explain with


diagram?
Inheritance
In object-oriented programming, inheritance enables new objects to take on the properties
of existing objects. A class that is used as the basis for inheritance is called a superclass or
base class or parent class. A class that inherits from a superclass is called a subclass or
derived class or child class.

Types of Inheritance:
1.Single Inheritance
When a class extends another one class only then we call it a single inheritance. The
below diagram shows that class B extends only one class which is A. Here A is a parent
class of B and B would be a child class of A.

CLASS A

CLASS B

2.Multiple Inheritance
Multiple Inheritance refers to the concept of one class inherits more than one base class.
The inheritance we learnt earlier had the concept of one base class or parent. The
problem with multiple inheritance is that the derived class will have to manage the
dependency on two base classes.

CLASS A

CLASS B

CLASS C

3.Multilevel Inheritance
Multilevel inheritance refers to a system in where one can inherit from a derived class,
thereby making this derived class the base class for the new class. As you can see in below
flow diagram C is subclass or child class of B and B is a child class of A.

CLASS A

CLASS B

CLASS C

4.Hierarchical Inheritance
In such kind of inheritance one class is inherited by many sub classes. In below example
class B,C and D inherits the same class A. A is parent class (or base class) of B,C & D.

CLASS A

CLASS B

CLASS D

CLASS C

5.Hybrid Inheritance
In simple terms you can say that Hybrid inheritance is a combination
Single and Multiple inheritance. A typical flow diagram would look like below.

of

CLASS A

CLASS B

CLASS C

CLASS D

2. Java doesn't support multiple inheritance.


Why?.How do we overcome it?
Java doesn't support Multiple Inheritance because it makes the code more
complex. The problem with multiple inheritance is that two classes may define different
ways of doing the same thing, and the subclass can't choose which one to pick. So to avoid
handling such complexities Java omitted the support for multiple Inheritance and Hybrid
Inheritance.
If you are using only classes then this is not allowed in java, however using
interfaces its possible to have multiple Inheritance and hybrid Inheritance in java

You might also like