Types of Inheritance in java with suitable example spring 2016||Object Oriented Programming

Layout Manager

What is inheritance? Explain types of Inheritance with suitable examples.

Inheritance in java is an apparatus in which one class accomplishes the belongings of another class. For example, a child inherits the characteristic of his/her parents.

Inheritance was invented in 1969 for java and is now used throughout many object-oriented programming languages such as Java, C++, or Python. Inheritance should not be confused with subtyping. In some languages, inheritance and subtyping agree whereas in other languages subtyping and inheritance differ. Inheritance is a commonly used mechanism for establishing subtype relationships.

Types of inheritance in JAVA

There are 5 types of inheritance in java. They are mentioned below:

1) Single inheritance

2) Multiple inheritances

3) Multilevel inheritance

4) Hierarchical inheritance

5) Hybrid inheritance

The above-mentioned types of inheritances are explained below:

1) Single inheritance

Single inheritance can be defined as an acquired class to inherit the basic procedure (members and variables) and behavior from a superclass. In other words, when a class expands to another class only, it is called single inheritance. For example, a dog falls under the animal class.

 

2) Multiple inheritances

Multiple inheritance is an attribute of some object-oriented computer programming language where an object or class can inherit property and traits from more than one parent object or parent class. For example, a baby dog inherits the dog class.

 

3) Multilevel inheritance

Multilevel inheritance refers to an apparatus in object-oriented advancement in which one can inherit from an acquired class. In other words, when a class expands another class, it is termed a multilevel inheritance.  For example, class C extends class B and class B extends class A then this type of inheritance is known as multilevel inheritance.

 

4) Hierarchical inheritance

When more than one class inherits the same class then it is called hierarchical inheritance. In other words, it is a kind of inheritance where more than one class is inherited from a single-parent or base class. For example, Physics, Chemistry, Biology are derived from Science.

 

5) Hybrid inheritance

Hybrid inheritance is a union of multiple inheritance and multilevel inheritance. A class is obtained from two classes as in multiple inheritances. Simply, hybrid inheritance is a combination of single and multiple inheritances. For example when class A and B extend class C & another class D extend class A then this is a hybrid inheritance.

 

Be the first to comment

Leave a Reply

Your email address will not be published.


*