
In this blog we will cover various types of inheritance that are supported by java in details .Programmers have the flexibility to choose any type of inheritance based on their specific requirements.
Prior to beginning this tutorial, it is recommended to refer to the “Inheritance in Java” tutorial if you are unfamiliar with the concept of inheritance in Java.
Here are the different types of inheritance supported in Java:
- Single inheritance
- Multilevel inheritance
- Hierarchical inheritance
- Multiple inheritance(Supported using interfaces, not by classes)
- Hybrid inheritance(Combination two or more of above inheritance types)
Single Inheritance In Java:
- When one class inherits properties and behaviors of only one another class. single inheritance means that a class can have only one parent class

Below example demonstrates how single inheritance allows a subclass to inherit features from its superclass
class Vehicle {
void startVehicle() {
System.out.println("Vehicle started");
}
}
class Car extends Vehicle {
void startCar() {
System.out.println("Car started");
}
}
public class Main {
public static void main(String[] args) {
Car car = new Car();
car.startVehicle(); // Calls the startVehicle() method of the superclass Vehicle.
car.startCar(); // Calls the startCar() method of the subclass Car.
}
}
Output :
Vehicle started
Car started
Multilevel Inheritance:
- When a class extends another class that is already extended from an different class is called multi-level inheritance . This creates a chain of inheritance , in this case subclass acts as a superclass of another class.

Below the example of multi level inheritance in Java the provided code demonstrates a simple example of multilevel inheritance in Java. The SportsCar
class inherits features from both its direct parent class (Car
) and its ancestor class (Vehicle
).
// Step 1: Create the top-level class 'Vehicle'
class Vehicle {
void start() {
System.out.println("Vehicle started");
}
}
// Step 2: Create the subclass 'Car' which inherits from 'Vehicle'
class Car extends Vehicle {
void drive() {
System.out.println("Car is being driven");
}
}
// Step 3: Create another subclass 'SportsCar' which inherits from 'Car'
class SportsCar extends Car {
void accelerate() {
System.out.println("Sports car is accelerating");
}
}
public class Main {
public static void main(String[] args) {
SportsCar sportsCar = new SportsCar();
sportsCar.start(); // Calls the start() method from 'Vehicle'.
sportsCar.drive(); // Calls the drive() method from 'Car'.
sportsCar.accelerate();// Calls the accelerate() method specific to 'SportsCar'.
}
}
Output:
Vehicle started
Car is being driven
Sports car is accelerating
Hierarchical inheritance:
- When more than one sub-class inherits the property of a single superclass class. Look at the below diagram to understand hierarchical inheritance where Class A is a super class, B is a subclass inherited from class A, and C is a subclass it also inherits from class A.

The below code defines four classes: A (the superclass), B (a subclass of A), C (a subclass of A), and D (a subclass of A). The main method creates objects of classes B, C, and D and calls their respective methods. Each subclass inherits the method methodA()
from the superclass A and provides its own implementation for its specific method
// Class A (Superclass)
class A {
void methodA() {
System.out.println("Method A from class A (Superclass)");
}
}
// Class B (Subclass of A)
class B extends A {
void methodB() {
System.out.println("Method B from class B (Subclass of A)");
}
}
// Class C (Subclass of A)
class C extends A {
void methodC() {
System.out.println("Method C from class C (Subclass of A)");
}
}
// Class D (Subclass of A)
class D extends A {
void methodD() {
System.out.println("Method D from class D (Subclass of A)");
}
}
// Main class
public class Main {
public static void main(String[] args) {
B b = new B();
C c = new C();
D d = new D();
b.methodA(); // Output: Method A from class A (Superclass)
b.methodB(); // Output: Method B from class B (Subclass of A)
c.methodA(); // Output: Method A from class A (Superclass)
c.methodC(); // Output: Method C from class C (Subclass of A)
d.methodA(); // Output: Method A from class A (Superclass)
d.methodD(); // Output: Method D from class D (Subclass of A)
}
}
Output:
Method A from class A (Superclass)
Method B from class B (Subclass of A)
Method A from class A (Superclass)
Method C from class C (Subclass of A)
Method A from class A (Superclass)
Method D from class D (Subclass of A)
Multiple Inheritance:
- When a class inherits the properties from many other classes in called Multiple inheritance . Java does not support multiple inheritance at class level which means a class cannot directly inherit from multiple classes.
- Multiple inheritance in java is supported through interfaces only, which means a class can inherit the features from more than one interfaces by using “implements” keyword . Java allows a class to implement any number of interfaces

In below example, we have three interfaces named A
, B
, and C
, representing different behaviors: flying, swimming, and walking, respectively. The D class implements all three interfaces (A
, B
, and C
), allowing it to have the ability to perform the behaviors defined in each of the interfaces.
// Interface A for flying behavior
interface A {
void fly();
}
// Interface B for swimming behavior
interface B {
void swim();
}
// Interface C for walking behavior
interface C {
void walk();
}
// Class representing an entity that can fly, swim, and walk
class D implements A, B, C {
@Override
public void fly() {
System.out.println("D is flying!");
}
@Override
public void swim() {
System.out.println("D is swimming!");
}
@Override
public void walk() {
System.out.println("D is walking!");
}
}
public class Main {
public static void main(String[] args) {
D entity = new D();
entity.fly();
entity.swim();
entity.walk();
}
}
Output:
D is flying!
D is swimming!
D is walking!
Hybrid Inheritance
- It combines two or more different types of inheritance Since Java doesn’t support multiple inheritance with classes, hybrid inheritance is also not possible with classes as it can lead to ambiguity and other issues.
- we can achieve hybrid inheritance only through interface in Java

In below example Hybrid inheritance is achieved through the Subclass
inheriting from Superclass
(class inheritance) and implementing both InterfaceA
and InterfaceB
(interface implementation).
This demonstrates the concept of hybrid inheritance, where multiple classes are linked together in an inheritance hierarchy through a combination of class inheritance and interface implementation.
class Superclass {
void display() {
System.out.println("This is the superclass.");
}
}
interface InterfaceA {
void methodA();
}
interface InterfaceB {
void methodB();
}
class Subclass extends Superclass implements InterfaceA, InterfaceB {
@Override
public void methodA() {
System.out.println("Implementation of InterfaceA's methodA");
}
@Override
public void methodB() {
System.out.println("Implementation of InterfaceB's methodB");
}
}
public class Main {
public static void main(String[] args) {
Subclass obj = new Subclass();
obj.display();
obj.methodA();
obj.methodB();
}
}
Output:
This is the superclass.
Implementation of InterfaceA's methodA
Implementation of InterfaceB's methodB