---
title: "What is Inheritance? what type of inheritance is supported in Java?"  
description: "What is Inheritance? what type of inheritance is supported in Java?"  
author: "Prateek sharma"  
published: 2018-04-06  
canonical: https://answers.mindstick.com/qa/40982/what-is-inheritance-what-type-of-inheritance-is-supported-in-java  
category: "technology"  
tags: ["java programming", "java"]  
reading_time: 5 minutes  

---

# What is Inheritance? what type of inheritance is supported in Java? 

## Answers

### Answer by NAMAN PANDEY

**INHERITANCE:** Inheritance is a process in which [properties](https://www.mindstick.com/articles/23331/nootropics-7-different-types-and-their-unique-properties) of parent class are inherited by the [child class](https://www.mindstick.com/forum/159389/how-to-remove-child-class-from-active-div).For example if there is a parent class and a child class and we declare a [variable](https://www.mindstick.com/articles/1807/objective-c-data-types-variables-object-creation) or method in the parent class we can use that in child class without declaring that variable or method again.There following are the types of inheritance:**1) SINGLE INHERITANCE** ![What is Inheritance? what type of inheritance is supported in Java?](https://answers.mindstick.com/questionanswer/2a797d1f-efb0-409b-b8ef-0b5ef28677c7/images/08265401-db07-41f1-a769-c710f7f6a81a.png)**\**Above diagram shows the concept of single inheritance.In single inheritance base class derive the properties from only one parent class.**Syntax:**

```
class subclass_name : access_mode base_class{  //body of subclass};
```

## EXAMPLE:

```
// C++ program to explain // Single inheritance#include <iostream>using namespace std;
// base classclass Vehicle {  public:    Vehicle()    {      cout << "This is a Vehicle" << endl;    }};

// sub class derived from two base classesclass Car: public Vehicle{
};
// main functionint main(){     // creating object of sub class will    // invoke the constructor of base classes    Car obj;    return 0;}
Output:This is a vehicle
```

## 2) MULTIPLE INHERITANCE:

![What is Inheritance? what type of inheritance is supported in Java?](https://answers.mindstick.com/questionanswer/2a797d1f-efb0-409b-b8ef-0b5ef28677c7/images/04f7a5f7-1ece-4000-aabf-298cff82506a.jpeg)**\**

In [multiple inheritance](https://www.mindstick.com/forum/2519/java-multiple-inheritance) properties of sub/chlid class are derived from from two super/parent classes.

## EXAMPLE:

```
// C++ program to explain // multiple inheritance#include <iostream>using namespace std;// first base classclass Vehicle {  public:    Vehicle()    {      cout << "This is a Vehicle" << endl;    }};
// second base classclass FourWheeler {  public:    FourWheeler()    {      cout << "This is a 4 wheeler Vehicle" << endl;    }};
// sub class derived from two base classesclass Car: public Vehicle, public FourWheeler {
};
// main functionint main(){     // creating object of sub class will    // invoke the constructor of base classes    Car obj;    return 0;}
Output:This is a VehicleThis is a 4 wheeler Vehicle
```

## 3) MULTILEVEL INHERITANCE:

![What is Inheritance? what type of inheritance is supported in Java?](https://answers.mindstick.com/questionanswer/2a797d1f-efb0-409b-b8ef-0b5ef28677c7/images/1db5edcc-c046-4f1a-806f-27d6a6693ba4.png)**\**

In multilevel inheritance,a derived class is derived from another base class.

## EXAMPLE:

```
// C++ program to implement // Multilevel Inheritance
#include <iostream>using namespace std;
// base classclass Vehicle {  public:    Vehicle()    {      cout << "This is a Vehicle" << endl;    }};
class fourWheeler: public Vehicle{ public:    fourWheeler()    {      cout<<"Objects with 4 wheels are vehicles"<<endl;    }
};
// sub class derived from two base classesclass Car: public fourWheeler{   public:     car()     {       cout<<"Car has 4 Wheels"<<endl;     }};
// main functionint main(){     //creating object of sub class will    //invoke the constructor of base classes    Car obj;    return 0;}
output:This is a VehicleObjects with 4 wheels are vehiclesCar has 4 Wheels
```

## 4) HIERARCHICAL INHERITANCE:

![What is Inheritance? what type of inheritance is supported in Java?](https://answers.mindstick.com/questionanswer/2a797d1f-efb0-409b-b8ef-0b5ef28677c7/images/b4fb305c-3ce6-4095-a2ca-2d04c6e3dcc1.png)**\**

In hierarchical inheritance,more than one [sub class](https://answers.mindstick.com/qa/92538/what-are-the-base-class-sub-class-and-superclass) is inherited from a single [base class](https://www.mindstick.com/interview/1817/what-is-a-base-class). i.e. more than one [derived class](https://answers.mindstick.com/qa/30686/what-is-a-base-class-and-derived-class) is created from a single base class.

## EXAMPLE:

```
// C++ program to implement // Hierarchical Inheritance#include <iostream>using namespace std; // base classclass Vehicle {  public:    Vehicle()    {      cout << "This is a Vehicle" << endl;    }};
// first sub class class Car: public Vehicle
{
};
// second sub classclass Bus: public Vehicle{
};
// main functionint main(){     // creating object of sub class will    // invoke the constructor of base class    Car obj1;    Bus obj2;    return 0;}
Output:This is a VehicleThis is a Vehicle
```

## 5) HYBRID INHERITANCE:

![What is Inheritance? what type of inheritance is supported in Java?](https://answers.mindstick.com/questionanswer/2a797d1f-efb0-409b-b8ef-0b5ef28677c7/images/beb0b030-602a-4bf4-a77b-eb69710650de.png)**\**

Hybrid Inheritance is implemented by combining more than one type of inheritance. For example: Combining Hierarchical inheritance and Multiple Inheritance.

## EXAMPLE:

```
// C++ program for Hybrid Inheritance
#include <iostream>using namespace std;
// base class class Vehicle
{  public:
    Vehicle()    {      cout << "This is a Vehicle" << endl;
    }
};
//base classclass Fare{    public:    Fare()    {        cout<<"Fare of Vehicle\n";    }};
// first sub class class Car: public Vehicle{
};
// second sub classclass Bus: public Vehicle, public Fare{
};
// main functionint main(){     // creating object of sub class will    // invoke the constructor of base class    Bus obj2;    return 0;}
Output:This is a VehicleFare of Vehicle
```

## TYPES OF INHERITANCE SUPPORTED BY JAVA:

Three types of inheritance are supported by java which are:

1)Single Inheritance

2)Multilevel Inheritance

3)Hierarchical Inheritance

There are two more types of inheritance supported by java but through **interface** only:

1)Multiple Inheritance

2)Hybrid Inheritance

The reason that Java does not support multiple inheritances is that of the problem known as **"diamond problem"**.

## \

## \

## \

## \

## \

**\****\**\


---

Original Source: https://answers.mindstick.com/qa/40982/what-is-inheritance-what-type-of-inheritance-is-supported-in-java

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
