top of page

What are the 5 types of Inheritance in Java?

As a programmer, you must have come across the term "Inheritance” in Java!

Inheritance is the method by which one class is allowed to inherit or access the data or properties of another class. It is a core concept in OOP (Object-Oriented Programming).

By using the inheritance techniques, we let classes with similar properties to an already existing class inherit them.


There are 5 types of inheritance that you should know about.


Important Terminologies:


Before we dive into the 5 types of inheritance in Javascript, let us look at some essential terminologies and their meanings:

  1. Class: A Class consists of objects that share some common properties.

  2. Superclass: A Super Class is the class from which the said features are inherited. It is also known as the parent class and base class since it is from where data is inherited.

  3. Subclass: The Class that inherits the properties from the superclass is called the Sub Class. It is also known as the child class and derived class since it inherits the data from the parent class.

  4. Reusability: When we want to make a class that may have some common properties or codes of another class, we can use the already existing class to make this new one. This is the concept of Reusability.

The general format of inheritance:

class​ superclass

{

// superclass data variables

// superclass member functions

}

class​ subclass ​extends​ superclass

{

// subclass data variables

// subclass member functions

}

Types of inheritance:

Conventionally, there are 5 distinct types of inheritance in Java. For better understanding, we will name the parent class as Class A and the derived or child classes as Class B, C, D, etc.

  • Single Inheritance:

The Single Inheritance is regarded as the most basic and easiest type of Java Inheritance. While using single inheritance, only one parent and one child class are involved. The child class simply inherits the methods and data members of the parent class.

CLASS A ---- CLASS B

Here is the syntax for single inheritance:

class base class

{

.... methods

}

class derivedClass name extends baseClass

{

methods ... along with this additional feature

}

  • Multi-level inheritance:

As the name suggests, there are multiple levels of inheritance in this type. The difference between multi-level and single inheritance is seen here. One derived class inherits from one parent or base class. The derived class also acts as a base class for another class.


Recent Posts

See All

Commentaires


bottom of page