Blog header background

Types of Inheritance in Java – Single vs. Multiple (With Examples)

Updated on April 16, 2026

14 min read

Copy link
Share on WhatsApp

Inheritance is one of the four pillars of OOP in Java – alongside abstraction, polymorphism, and encapsulation. Understanding the types of inheritance in java is essential for any developer building modular, reusable, and maintainable code. Java supports five inheritance models, each serving a distinct design purpose.

This article covers every type of inheritance and its types in java with clear syntax, working code examples, and a comparison table – giving you everything you need to apply the right inheritance model in your projects.

But before we begin, you can brush up your knowledge on Java and its array by reading this HeroVired article on – What are Arrays in Java.

What is Inheritance in Java?

Inheritance in Java is a mechanism where one class acquires the properties (fields) and behaviours (methods) of another class. It models the is-a relationship – a Dog is-a Animal, a Puppy is-a Dog. The class being inherited from is the superclass (parent class), and the class doing the inheriting is the subclass (child class). Java uses the extends keyword to implement inheritance.

brochure-banner-bg

POSTGRADUATE PROGRAM IN

Multi Cloud Architecture & DevOps

Master cloud architecture, DevOps practices, and automation to build scalable, resilient systems.

Why use inheritance?

Code Reuse: Write shared behaviour once in the parent class – all subclasses inherit it automatically

Method Overriding: Subclasses can redefine parent methods to provide specialised behaviour (runtime polymorphism)

Logical Organisation: Inheritance mirrors real-world taxonomies – making code structure intuitive and readable

Extensibility: New classes can extend existing ones without modifying the original code (open/closed principle)

Types of Inheritance in Java

The different types of inheritance in java are determined by the number of parent and child classes involved and how the inheritance chain is structured. Java supports five inheritance types – four through classes and one exclusively through interfaces. The five types of inheritance in java with example are covered below.

1. Single Inheritance

Single inheritance is the simplest of all types of inheritance in java. A single child class inherits from exactly one parent class. This is the most commonly used inheritance model in Java and provides a clean, unambiguous class hierarchy.

Structure: Class B (child) extends Class A (parent). Class B gains all non-private fields and methods of Class A.

Property

Detail

Parent classes

1

Child classes

1

Complexity

Low

Java support

Full (classes and interfaces)

Use case

Extending a base class with new specialised behaviour

Syntax and Example:

// types of inheritance in java with example - Single Inheritance

class Animal {

void eat() {

System.out.println("Animal is eating");

}

}

class Dog extends Animal {

void bark() {

System.out.println("Dog is barking");

}

}

public class TestSingleInheritance {

public static void main(String[] args) {

Dog d = new Dog();

d.bark(); // Output: Dog is barking

d.eat(); // Output: Animal is eating (inherited from Animal)

}

}

Output: Dog is barking | Animal is eating

In this example, Dog inherits the eat() method from Animal without redefining it – a direct demonstration of code reuse through single inheritance.

2. Multilevel Inheritance in Java

Multilevel inheritance in java creates a chain of inheritance across three or more levels. Class C inherits from Class B, which itself inherits from Class A. This creates a linear ancestor hierarchy – each class adds to the behaviour of the one above it.

In a multilevel inheritance example in java: a Puppy is a Dog, and a Dog is an Animal. The Puppy class inherits from Dog, which in turn inherits from Animal. This is the classic example of multilevel inheritance – Puppy gains all methods from both Dog and Animal.

Property

Detail

Levels

3 or more

Chain direction

Linear – A → B → C → …

Java support

Full

Use case

Progressively specialised class hierarchies (Vehicle → Car → ElectricCar)

Key rule

Each class inherits all accessible members from all ancestors up the chain

Syntax and Example – Classic Multilevel Inheritance Example in Java:

// multilevel inheritance in java - 3-level chain

class Animal {

void eat() {

System.out.println("Animal is eating");

}

}

class Dog extends Animal {

void bark() {

System.out.println("Dog is barking");

}

}

class Puppy extends Dog { // Puppy → Dog → Animal

void weep() {

System.out.println("Puppy is weeping");

}

}

public class TestMultiLevel {

public static void main(String[] args) {

Puppy p = new Puppy();

p.weep(); // Output: Puppy is weeping

p.bark(); // Output: Dog is barking (inherited from Dog)

p.eat(); // Output: Animal is eating (inherited from Animal)

}

}

Extended multilevel inheritance example in java – Vehicle hierarchy:

// example of multilevel inheritance - Vehicle → Car → ElectricCar

class Vehicle {

void start() { System.out.println("Vehicle started"); }

}

class Car extends Vehicle {

void drive() { System.out.println("Car is driving"); }

}

class ElectricCar extends Car {

void charge() { System.out.println("ElectricCar is charging"); }

}

public class TestElectric {

public static void main(String[] args) {

ElectricCar ec = new ElectricCar();

ec.charge(); // Output: ElectricCar is charging

ec.drive(); // Output: Car is driving

ec.start(); // Output: Vehicle started

}

}

This second multilevel inheritance example in java shows a real-world vehicle hierarchy – a practical pattern used in automotive simulation systems, game engines, and manufacturing software. In each multilevel inheritance in java scenario, the deepest subclass has access to the cumulative behaviour of every ancestor in the chain.

3. Multiple Inheritance (via Interfaces)

Multiple inheritance is where a class inherits from more than one parent. Java does not support multiple inheritance through classes (to avoid the Diamond Problem), but fully supports it through interfaces. A class can implement any number of interfaces, gaining all their abstract method contracts simultaneously.

Note: Java intentionally omits multiple class inheritance to prevent ambiguity when two parent classes define the same method. Interfaces solve this because they define contracts (method signatures), not implementations – the implementing class always provides its own concrete method body.

// multiple inheritance in java via interfaces

interface Flyable {

void fly();

}

interface Swimmable {

void swim();

}

// Duck implements BOTH interfaces - multiple inheritance via interface

class Duck implements Flyable, Swimmable {

@Override

public void fly() { System.out.println("Duck is flying"); }

@Override

public void swim() { System.out.println("Duck is swimming"); }

}

public class TestMultiple {

public static void main(String[] args) {

Duck duck = new Duck();

duck.fly(); // Output: Duck is flying

duck.swim(); // Output: Duck is swimming

}

}

This is the standard pattern for achieving multiple inheritance in Java. Any number of interfaces can be combined – the implementing class is responsible for providing concrete implementations of all abstract methods. Default methods (Java 8+) in interfaces add another dimension, but explicit overriding resolves any conflicts.

4. Hierarchical Inheritance in Java

Hierarchical inheritance in java occurs when multiple child classes inherit from a single parent class. All subclasses share the common behaviour defined in the parent, while each can also add its own specialised methods. This creates a fan-out structure – one parent, many children.

Property

Detail

Parent classes

1

Child classes

2 or more

Structure

Fan-out – one parent, multiple children

Java support

Full

Use case

Shared base behaviour with specialised subclass implementations

// hierarchical inheritance in java

class Animal {

void eat() { System.out.println("Animal is eating"); }

}

class Dog extends Animal {

void bark() { System.out.println("Dog is barking"); }

}

class Cat extends Animal {

void meow() { System.out.println("Cat is meowing"); }

}

class Bird extends Animal {

void chirp() { System.out.println("Bird is chirping"); }

}

public class TestHierarchical {

public static void main(String[] args) {

Dog d = new Dog();

d.bark(); // Output: Dog is barking

d.eat(); // Output: Animal is eating

Cat c = new Cat();

c.meow(); // Output: Cat is meowing

c.eat(); // Output: Animal is eating

}

}

In this hierarchical inheritance in java example, Dog, Cat, and Bird all extend Animal and inherit eat(). Each subclass adds its own unique behaviour. This is one of the most common inheritance patterns in enterprise Java – for example, SavingsAccount, CurrentAccount, and FixedDepositAccount all extending a base BankAccount class.

5. Hybrid Inheritance in Java

Hybrid inheritance in java is a combination of two or more inheritance types – most commonly hierarchical + multilevel, or hierarchical + multiple. Java supports hybrid inheritance through interfaces when multiple inheritance is involved.

Hybrid inheritance in java via classes alone is limited to combinations that do not require multiple class parents (e.g., hierarchical + multilevel is fully supported). When multiple parents are needed, interfaces must be used – making interface-based hybrid inheritance the standard approach in production Java code.

// hybrid inheritance in java - hierarchical + multiple via interfaces

interface Flyable {

void fly();

}

class Animal {

void eat() { System.out.println("Animal is eating"); }

}

// Dog inherits from Animal AND implements Flyable

// (hierarchical from Animal's perspective + multiple via interface)

class FlyingDog extends Animal implements Flyable {

@Override

public void fly() { System.out.println("FlyingDog is flying"); }

void bark() { System.out.println("FlyingDog is barking"); }

}

class Cat extends Animal {

void meow() { System.out.println("Cat is meowing"); }

}

public class TestHybrid {

public static void main(String[] args) {

FlyingDog fd = new FlyingDog();

fd.fly(); // Output: FlyingDog is flying

fd.bark(); // Output: FlyingDog is barking

fd.eat(); // Output: Animal is eating (from Animal)

Cat c = new Cat();

c.meow(); // Output: Cat is meowing

c.eat(); // Output: Animal is eating (from Animal)

}

}

Hybrid inheritance in java is the most flexible and complex model. It is commonly used in framework design – for example, Spring’s component hierarchy combines class-based hierarchical inheritance with multiple interface implementations to achieve modularity and testability.

Comparison: All Types of Inheritance in Java

Use this table as a quick reference for the different types of inheritance in java – covering structure, Java support status, and ideal use cases.

Type

Structure

Classes Involved

Java Support

Keyword

Best Use Case

Single

A → B

1 parent, 1 child

Full

extends

Extending a single base class

Multilevel

A → B → C

Chain of 3+

Full

extends

Progressive specialisation chains

Multiple

A + B → C

2+ parents, 1 child

Via interfaces only

implements

Combining unrelated capabilities

Hierarchical

A → B, A → C, A → D

1 parent, many children

Full

extends

Shared base with varied subclasses

Hybrid

Combination of above

Varies

Partial (interfaces for multi)

extends + implements

Complex framework or system design

The types of inheritance in java with example covered in this guide map directly to this table. When choosing an inheritance model, the primary question is: how many parent classes does the child need? If one → single or hierarchical. If a chain → multilevel. If multiple capabilities from unrelated sources → interfaces.

skill-test-section-bg

82.9%

of professionals don't believe their degree can help them get ahead at work.

Why Java Does Not Support Multiple Class Inheritance

A common exam and interview question about inheritance and its types in java: why does Java prohibit multiple class inheritance? The answer is the Diamond Problem.

The Diamond Problem: Suppose Class C extends both Class A and Class B. Both A and B define a method display(). When C.display() is called, the compiler cannot determine which parent’s version to use – creating an irresolvable ambiguity.

// This is NOT valid in Java - demonstrates why:

class A { void display() { System.out.println("A"); } }

class B { void display() { System.out.println("B"); } }

// class C extends A, B ← COMPILE ERROR: Java does not allow this

// Which display() does C inherit? A's or B's? - The Diamond Problem

// Java's solution: use interfaces

interface A { default void display() { System.out.println("A"); } }

interface B { default void display() { System.out.println("B"); } }

class C implements A, B {

@Override

public void display() {

A.super.display(); // Explicitly choose which default to use

// Output: A

}

}

Interfaces resolve the Diamond Problem by requiring the implementing class to override any conflicting default methods explicitly. This gives Java the flexibility of multiple inheritance without the ambiguity that makes it dangerous in C++.

Language

Multiple Class Inheritance

Solution for Ambiguity

Java

Not supported

Use interfaces (implements multiple)

C++

Supported

Virtual inheritance (error-prone, complex)

Python

Supported

MRO (Method Resolution Order – C3 linearisation)

C#

Not supported

Use interfaces (same as Java)

Kotlin

Not supported

Use interfaces with default methods

Inheritance and Its Types in Java – Common Mistakes

Developers new to inheritance and its types in java frequently make these mistakes. Knowing them ahead of time prevents bugs that are difficult to trace:

Attempting multiple class inheritance: Writing class C extends A, B is a compile error in Java. Use interfaces for multiple capability inheritance.

Confusing multilevel and multiple inheritance: Multilevel = linear chain (A→B→C). Multiple = multiple parents (A+B→C). They are structurally different.

Not calling super() correctly: In multilevel inheritance, if a parent constructor takes arguments, the child must explicitly call super(args) – otherwise a compile error occurs.

Circular inheritance: A class cannot extend itself or form a cycle (A extends B, B extends A) – this is a compile error.

Overusing inheritance over composition: Inheritance implies a strict is-a relationship. If the relationship is has-a, use composition instead. Overusing inheritance creates brittle, tightly coupled hierarchies.

Private member visibility: Private fields and methods of a parent class are NOT inherited by the child. They exist in the child object but are not directly accessible – use getters/setters or protected access.

Conclusion

Mastering the types of inheritance in java – single, multilevel inheritance in java, multiple (via interfaces), hierarchical inheritance in java, and hybrid inheritance in java – gives you the structural foundation to design clean, reusable, and scalable Java applications.

The key takeaways: use single inheritance for straightforward parent-child extension; use multilevel inheritance in java for progressive specialisation chains; use interfaces for multiple inheritance; use hierarchical when many subclasses share a common base; and use hybrid when complex systems need combinations of the above.

Inheritance is a powerful tool, but always ask: is this a genuine is-a relationship? If yes, inheritance is the right model. If it’s a has-a relationship, prefer composition. This distinction is at the heart of clean OOP design in Java.

To build full production-grade Java expertise, explore the Certificate Program in Application Development powered by Hero Vired – covering Java, full-stack development, cloud, and more.

People Also Ask

What are the 5 types of inheritance in Java?

The five types of inheritance in java are: Single (one parent → one child), Multilevel (chain: A→B→C), Multiple (multiple parents → one child, via interfaces only), Hierarchical (one parent → multiple children), and Hybrid (combination of two or more types).

Does Java support multiple inheritance?

Java does not support multiple inheritance through classes to avoid the Diamond Problem. However, Java fully supports multiple inheritance through interfaces – a class can implement any number of interfaces simultaneously.

What is the difference between multilevel and hierarchical inheritance in Java?

Multilevel inheritance in java creates a linear chain: Class A → Class B → Class C (each inheriting from the one above). Hierarchical inheritance in java creates a fan-out: Class A is the parent of Class B, Class C, and Class D simultaneously. The key distinction is the direction of inheritance – linear chain vs. one-to-many.

What is an example of multilevel inheritance in Java?

A classic multilevel inheritance example in java: Animal → Dog → Puppy. Dog extends Animal and inherits eat(). Puppy extends Dog and inherits both eat() and bark(). A Puppy object can call all three methods – weep(), bark(), and eat() – demonstrating the cumulative inheritance chain.

What is hybrid inheritance and is it supported in Java?

Hybrid inheritance in java is a combination of two or more inheritance types. Java supports hybrid inheritance when no combination requires multiple class parents. When multiple class inheritance is involved, interfaces must be used instead – making interface-based hybrid patterns the standard approach in Java frameworks like Spring.

FAQs
What is the most common type of inheritance in Java?
The most common type of inheritance in Java is hybrid inheritance. Interfaces are the sole means through which it is possible because Java does not enable multiple inheritances. In essence, it combines straightforward, numerous, and hierarchical inheritances.
What are the types of inheritance in Java?
The types of Inheritance in Java are: 
  • Single-level inheritance.
  • Multi-level Inheritance.
  • Hierarchical Inheritance.
  • Multiple Inheritance.
  • Hybrid Inheritance.
Why Doesn’t Java Support Multiple Inheritance?
As we have read about types of inheritance in Java. Java doesn’t enable multiple inheritances in classes since it can result in diamond difficulties, and there are easier ways to accomplish the same goal without resorting to a complicated solution.
Why is Multiple Inheritance not allowed?
As we have read about types of inheritance in Java in detail. To avoid ambiguity, this is the justification. Consider a scenario in which class B extends classes C and A, and both classes A and C share the display() method. The Java compiler is currently unable to determine which display method to inherit. Java does not provide multiple inheritances to avoid this scenario.
What is the major use of Multi-level Inheritance?
As we have read about types of inheritance in Java. Using the hierarchical approach, the classes provide a number of features, properties, methods, etc., making it easier for derived classes to inherit features via the parent class.

Updated on April 16, 2026

Link
Loading related articles...