Types of Inheritance in Java with Examples

The five types of inheritance in Java are single, multilevel, hierarchical, multiple and hybrid. Single, multilevel and hierarchical are supported directly through classes using the extends keyword. Multiple and hybrid inheritance are supported only through interfaces, because Java blocks multiple class inheritance to prevent the diamond problem.

  • Key Takeaway 1: Java has five inheritance types, but only single, multilevel and hierarchical are supported directly via classes.
  • Key Takeaway 2: Multiple inheritance in Java is achieved using interfaces, not class extension.
  • Key Takeaway 3: The diamond problem is the core reason Java blocks multiple class inheritance.
  • Key Takeaway 4: Hybrid inheritance combines two or more types and is also implemented via interfaces in Java.
  • Key Takeaway 5: According to the Stack Overflow Developer Survey 2024, Java remains one of the top five most-used programming languages globally, making these fundamentals genuinely career-relevant.

Overview of Inheritance Types in Java

Inheritance lets one class acquire the properties and methods of another. The class that gives is called the parent class (or superclass), and the class that receives is the child class (or subclass). This reduces code duplication and makes large codebases easier to maintain.

The five types of inheritance in Java map to distinct relationships between classes. Before you write a single line, you need to know which type fits your design. Using the wrong one is a common mistake that creates messy coupling and makes unit testing painful.

Five Types of Inheritance in Java: Class and Interface Support
Inheritance Type Supported via Classes? Supported via Interfaces? Key Characteristic
Single Yes Yes One child, one parent
Multilevel Yes Yes Chain of parent-child relationships
Hierarchical Yes Yes Multiple children, one parent
Multiple No Yes One child inherits from multiple parents
Hybrid No Yes Combination of two or more types

Oracle’s official Java SE documentation explicitly states that Java does not support multiple inheritance through classes to keep the language simple and to eliminate ambiguity. That design decision shapes how you structure every large Java project.

According to the JetBrains State of Developer Ecosystem 2023, Java is used by 57% of developers who work with JVM-based languages, confirming that OOP concepts like inheritance remain core professional skills rather than academic theory.

If you’re just getting started with programming concepts, it helps to first get comfortable with the software development tools you’ll need before diving deep into OOP.

Why Inheritance Matters in Real Projects and Indian Placements

In a typical enterprise Java application, you might have a base class Employee that holds common fields like name, ID and salary. Subclasses like Manager, Developer and Intern extend it without rewriting those fields. That’s hierarchical inheritance at work, and it’s everywhere in production code.

This topic is part of the GATE CS syllabus under Object-Oriented Programming and appears as a standard question in semester exams at universities affiliated with AKTU, Mumbai University and Anna University. Indian IT recruiters at Infosys, TCS, Wipro and HCL list Java OOP as a mandatory screening criterion in campus placement drives. According to AmbitionBox, the average salary for a Java developer in India in 2024 ranges from Rs 4.5 LPA at entry level to Rs 18 LPA at senior level, with OOP proficiency cited as a key differentiator in performance reviews.

A practical mistake beginners make is over-inheriting. Not every relationship should use inheritance. If class B only uses a few methods from class A but doesn’t truly represent an “is-a” relationship with class A, you should use composition instead. Interviewers at companies like Infosys, TCS and Wipro regularly ask about this distinction.

Single Inheritance and Multilevel Inheritance in Java with Examples

Single Inheritance

Single inheritance is the simplest form. One child class extends exactly one parent class. It’s the safest, most predictable form of inheritance and the one you’ll use most often.

Here’s a concrete example. You have a class Vehicle with a method startEngine(). A class Car extends Vehicle and inherits that method without redefining it. Car can then add its own method, say openSunroof(), that Vehicle doesn’t have.

class Vehicle {
    void startEngine() {
        System.out.println("Engine started");
    }
}

class Car extends Vehicle {
    void openSunroof() {
        System.out.println("Sunroof opened");
    }
}

This is single inheritance: one parent, one child, clean and unambiguous.

Multilevel Inheritance in Java

Multilevel inheritance creates a chain. Class A is the parent of Class B, and Class B is the parent of Class C. Class C inherits from both A and B through that chain, not directly from A.

Think of it like a family tree. Animal is the grandparent, Mammal extends Animal, and Dog extends Mammal. Dog gets the methods of both Animal and Mammal automatically.

class Animal {
    void breathe() {
        System.out.println("Breathing");
    }
}

class Mammal extends Animal {
    void feedMilk() {
        System.out.println("Feeding milk");
    }
}

class Dog extends Mammal {
    void bark() {
        System.out.println("Barking");
    }
}

A Dog object can call breathe(), feedMilk() and bark(). That’s the power of multilevel inheritance. Keep the chain to three or four levels maximum in real projects or the code becomes hard to trace and debug.

Speaking of debugging, if you’re running into unexpected runtime issues in Java programs, the guide on Java exceptions and common runtime errors covers the most frequent problems and how to fix them.

Hierarchical Inheritance in Java with Example

Hierarchical inheritance means one parent class has multiple child classes. Each child class inherits from the same parent independently. The children don’t inherit from each other.

This is probably the most common pattern you’ll see in real codebases. Consider a university system (very relevant if you’re studying BSc Computer Science). A base class Shape has a method draw(). Three child classes, Circle, Rectangle and Triangle, each extend Shape and override draw() with their own logic.

class Shape {
    void draw() {
        System.out.println("Drawing a shape");
    }
}

class Circle extends Shape {
    void draw() {
        System.out.println("Drawing a circle");
    }
}

class Rectangle extends Shape {
    void draw() {
        System.out.println("Drawing a rectangle");
    }
}

class Triangle extends Shape {
    void draw() {
        System.out.println("Drawing a triangle");
    }
}

All three classes share the Shape parent. None of them knows about the others. That independence is what makes hierarchical inheritance clean and scalable.

Where Hierarchical Inheritance Shows Up in Real Work

In Android development, which is Java-based at its core, View is the parent class and dozens of UI elements like Button, TextView and ImageView extend it hierarchically. Every time you build an Android app, you’re using hierarchical inheritance whether you think about it or not.

According to the TIOBE Index for 2024, Java consistently ranks in the top four programming languages worldwide. That means hierarchical inheritance in Java isn’t just an exam topic; it’s a pattern you’ll encounter across Android, Spring Boot, enterprise backends and more.

Multiple Inheritance and Hybrid Inheritance in Java

Multiple Inheritance Using Interfaces and the Diamond Problem

Multiple inheritance is when one child class inherits from two or more parent classes. Java blocks this for classes deliberately. The reason is the diamond problem.

Imagine two parent classes, A and B, both defining a method called show(). A child class C tries to extend both. When you call c.show(), the compiler doesn’t know which version to pick. That ambiguity is the diamond problem, and Java’s designers chose to eliminate it at the language level rather than leave it to programmers to sort out at runtime.

Java solves multiple inheritance through interfaces. A class can implement any number of interfaces. If two interfaces have the same default method, you override it in the implementing class to resolve the conflict explicitly. That makes the decision yours, not the compiler’s guess.

interface Flyable {
    default void move() {
        System.out.println("Flying");
    }
}

interface Swimmable {
    default void move() {
        System.out.println("Swimming");
    }
}

class Duck implements Flyable, Swimmable {
    public void move() {
        Flyable.super.move(); // explicitly choosing
    }
}

Hybrid Inheritance in Java

Hybrid inheritance is a mix of two or more inheritance types. For example, combining hierarchical and multiple inheritance in one design. Because it involves multiple inheritance, hybrid inheritance is also only possible through interfaces in Java.

A practical example: a class FlyingFish implements both Flyable and Swimmable interfaces, while both interfaces extend a common Animal interface. That’s a hybrid structure. It’s common in framework design, plugin architectures and modular enterprise systems.

If you’re an MCA student or professional thinking about where these skills lead, understanding OOP at this depth is directly relevant to senior developer roles. You can see how that maps to career outcomes in the guide on jobs and salary after MCA.

Quick Comparison: Class vs Interface Inheritance in Java

Class Inheritance vs Interface Inheritance in Java
Feature Class Inheritance (extends) Interface Inheritance (implements)
Multiple parents allowed? No Yes
Inherits implementation? Yes Only default methods (Java 8+)
Diamond problem risk? Yes (blocked by compiler) Manageable via override
Use case Is-a relationship with shared code Capability contracts, multiple types

If you’re coming from C programming and this is your first deep look at OOP, the guide on how to write, compile and run a C program gives useful context on how procedural and object-oriented thinking differ.

Whether you’re choosing a career path as a full stack developer or software developer, solid OOP fundamentals like these are non-negotiable. Interviewers don’t just ask you to name the types; they ask you to design systems using them.

Frequently Asked Questions

What are the types of inheritance in Java?

Java supports five types of inheritance: single, multilevel, hierarchical, multiple and hybrid. Single, multilevel and hierarchical are supported directly through classes using the extends keyword. Multiple and hybrid inheritance are supported only through interfaces, since Java blocks multiple class inheritance to avoid the diamond problem.

Does Java support multiple inheritance?

Java does not support multiple inheritance through classes. A class can only extend one other class. Java does support multiple inheritance of type through interfaces, meaning a single class can implement multiple interfaces. This approach avoids the diamond problem while still giving you the flexibility of multiple-parent behaviour.

What is hierarchical inheritance with example?

Hierarchical inheritance is when multiple child classes extend a single parent class. For example, classes Circle, Rectangle and Triangle all extend a parent class Shape. Each child class independently inherits the parent’s methods and can override or extend them without knowing about the other sibling classes.

What is multilevel inheritance in Java?

Multilevel inheritance is when a class inherits from a class that is itself a subclass of another class, forming a chain. For example, Dog extends Mammal, and Mammal extends Animal. A Dog object inherits methods from both Mammal and Animal through this chain, not through direct extension.

What is hybrid inheritance in Java?

Hybrid inheritance is a combination of two or more types of inheritance in a single design. For example, a structure that mixes hierarchical and multiple inheritance. Because it involves multiple inheritance, Java only supports hybrid inheritance through interfaces, not through classes. It’s commonly used in framework and plugin architectures.

Is inheritance in Java asked in GATE and campus placements?

Yes. Inheritance in Java is part of the GATE CS syllabus under Object-Oriented Programming. It is also a standard topic in campus placement technical rounds at companies like TCS, Infosys, Wipro and HCL. Questions typically ask candidates to identify the inheritance type from a given class diagram or to write code that demonstrates a specific type.

Now you have a working mental model of all five types of inheritance in Java, which ones work with classes, which require interfaces, and why Java made those design choices. The types of inheritance in Java aren’t just theory; they show up directly in every Android app, Spring Boot service and enterprise Java system you’ll ever build or maintain.

  1. This week: Write a small Java program that implements all three class-based inheritance types using a real-world domain, such as a university system with students, teachers and departments.
  2. Next: Practice implementing multiple inheritance using interfaces with at least two conflicting default methods, then resolve the conflict manually.
  3. Then: Explore 3.0 University’s online certification courses in Cybersecurity, AI and Blockchain, where strong Java and OOP fundamentals underpin secure coding, AI model integration and smart contract development. If ethical hacking interests you, the CEH v13 AI online course builds on exactly the kind of programming rigour you’re developing here.

Last updated: June 2025. Reviewed by the 3University editorial team.

We create, review, and maintain educational content covering Cybersecurity, Ethical Hacking, Artificial Intelligence, Blockchain, Web3, and emerging technologies.

Read More Articles