BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

Types of inheritance in Java: Single,Multiple,Multilevel & Hybrid

Last Updated: September 11, 2022 by Chaitanya Singh | Filed Under: java

Below are Various types of inheritance in Java. We will see each one of them one by one with the help of examples and flow diagrams.

1) Single Inheritance

Single inheritance is damn easy to understand. When a class extends another one class only then we  call it a single inheritance. The below flow diagram shows that class B extends only one class which is A. Here A is a parent class of B and B would be  a child class of A.

Single Inheritance

Single Inheritance example program in Java

Class A
{
   public void methodA()
   {
     System.out.println("Base class method");
   }
}

Class B extends A
{
   public void methodB()
   {
     System.out.println("Child class method");
   }
   public static void main(String args[])
   {
     B obj = new B();
     obj.methodA(); //calling super class method
     obj.methodB(); //calling local method
  }
}

2) Multiple Inheritance

“Multiple Inheritance” refers to the concept of one class extending (Or inherits) more than one base class. The inheritance we learnt earlier had the concept of one base class or parent. The problem with “multiple inheritance” is that the derived class will have to manage the dependency on two base classes.

Multiple-Inheritance

Note 1: Multiple Inheritance is very rarely used in software projects. Using Multiple inheritance often leads to problems in the hierarchy. This results in unwanted complexity when further extending the class.

Note 2: Most of the new OO languages like Small Talk, Java, C# do not support Multiple inheritance. Multiple Inheritance is supported in C++.

3) Multilevel Inheritance

Multilevel inheritance refers to a mechanism in OO technology where one can inherit from a derived class, thereby making this derived class the base class for the new class. As you can see in below flow diagram C is subclass or child class of B and B is a child class of A. For more details and example refer – Multilevel inheritance in Java.

Multilevel-Inheritance

Multilevel Inheritance example program in Java

Class X
{
   public void methodX()
   {
     System.out.println("Class X method");
   }
}
Class Y extends X
{
public void methodY()
{
System.out.println("class Y method");
}
}
Class Z extends Y
{
   public void methodZ()
   {
     System.out.println("class Z method");
   }
   public static void main(String args[])
   {
     Z obj = new Z();
     obj.methodX(); //calling grand parent class method
     obj.methodY(); //calling parent class method
     obj.methodZ(); //calling local method
  }
}

4) Hierarchical Inheritance

In such kind of inheritance one class is inherited by many sub classes. In below example class B,C and D inherits the same class A. A is parent class (or base class) of B,C & D. Read More at – Hierarchical Inheritance in java with example program.

Hierarchical-Inheritance

5) Hybrid Inheritance

In simple terms you can say that Hybrid inheritance is a combination of Single and Multiple inheritance. A typical flow diagram would look like below. A hybrid inheritance can be achieved in the java in a same way as multiple inheritance can be!! Using interfaces. yes you heard it right. By using interfaces you can have multiple as well as hybrid inheritance in Java.

Read the full article here – hybrid inheritance in java with example program.

Hybrid-inheritance

Top Related Articles:

  1. Multithreading in java with examples
  2. Java – Static Class, Block, Methods and Variables
  3. Final Keyword In Java – Final variable, Method and Class
  4. How to write to file in Java using BufferedWriter
  5. Constructor Overloading in Java with examples

Tags: Java-OOPs

About the Author

I have 15 years of experience in the IT industry, working with renowned multinational corporations. Additionally, I have dedicated over a decade to teaching, allowing me to refine my skills in delivering information in a simple and easily understandable manner.

– Chaitanya

Comments

  1. sami says

    April 21, 2014 at 5:56 PM

    it is one of the most beautiful notes. i easily understand. Thanks for this……

    Reply
  2. yuvraj patil says

    May 22, 2014 at 6:06 PM

    explain the Hybrid Inheritance with example in details ?
    thnx

    Reply
  3. Kultaran singh says

    May 29, 2014 at 2:13 AM

    good example in easy way

    Reply
  4. joshy says

    August 1, 2014 at 11:21 AM

    i did’t understand multiple inheritence in java concept …
    plz give me brief information of multiple inheritance in java……

    Reply
    • Chaitanya Singh says

      November 15, 2014 at 8:40 AM

      Refer this article: https://beginnersbook.com/2013/05/java-multiple-inheritance/

      Reply
    • nishant khari says

      March 30, 2016 at 6:04 PM

      multiple-inheritance supported in java through interface ,so go through interface topic.

      Reply
    • mani says

      January 26, 2017 at 9:22 AM

      java does not support multiple inheritence

      Reply
  5. aslamraza says

    September 4, 2014 at 7:31 AM

    please list out the programming languages that support different inheritances
    thank you !!!!!!!!!!!!!!!

    Reply
  6. sanjay thakor says

    September 11, 2014 at 6:34 PM

    good material for easy self learning

    Reply
  7. yogini says

    August 5, 2015 at 3:26 AM

    finally what is the answer? does java supports multiple inheritance?????????????????????? because i cant understand ..on the top its written that java does support but on the otherhand it says that it doesnt.

    Reply
    • Shubham Sikarwar says

      October 31, 2015 at 12:18 AM

      Java does not support Multiple inheritance or Hybrid inheritance directly!!!!
      BUT……it can be implemented using Interfaces as described above in the article!!!(Jugaad)!!

      Reply
    • Mark says

      February 16, 2016 at 10:37 AM

      There is no multiple inheritance in java, even with interface. we are indirectly just achieving it because in interface we are just extending only the empty methods, not the body.

      Reply
  8. Tushar Jadhav says

    August 21, 2015 at 9:55 AM

    java does not support Multiple Inheritance

    Reply
  9. Lenin says

    September 17, 2015 at 7:02 AM

    I need the multiple, hybrid, hierarchical inheritance example programs….

    Reply
    • Chaitanya Singh says

      September 17, 2015 at 12:01 PM

      Hey Lenin, Please refer the links provided in the post for the examples of each type of inheritance.

      Reply
  10. Brian says

    September 23, 2015 at 10:16 PM

    You DO NOT inherit from interfaces!! Nothing is defined in an interface therefore you have nothing to inherit. You IMPLEMENT an interface, and yes you can implement multiple interfaces in Java. Java DOES NOT allow for multiple inheritance or hybrid inheritance (diamond inheritance).

    Reply
  11. Arti Priya says

    September 14, 2016 at 3:38 PM

    ONE OF THE BEST SITE,
    KEEP IT UP GUYS!!

    Reply
  12. gayathri says

    November 4, 2016 at 11:24 AM

    I need hierarchical example program

    Reply
  13. Sabina says

    March 23, 2017 at 10:26 AM

    Amazing notes!Thank you! Simple and easy to understand with examples :)

    Reply
  14. Jay says

    June 17, 2017 at 12:35 PM

    Nice and helpful brief explanation, even for beginner or for some one who just wants to brush up the knowledge.

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Java Tutorial

Java Introduction

  • Java Index
  • Java Introduction
  • History of Java
  • Features of Java
  • C++ vs Java
  • JDK vs JRE vs JVM
  • JVM - Java Virtual Machine
  • First Java Program
  • Variables
  • Data Types
  • Operators

Java Flow Control

  • Java If-else
  • Java Switch-Case
  • Java For loop
  • Java while loop
  • Java do-while loop
  • Continue statement
  • break statement

Java Arrays

  • Java Arrays

OOPs Concepts

  • OOPs Concepts
  • Constructor
  • Java String
  • Static keyword
  • Inheritance
  • Types of inheritance
  • Aggregation
  • Association
  • Super Keyword
  • Method overloading
  • Method overriding
  • Overloading vs Overriding
  • Polymorphism
  • Types of polymorphism
  • Static and dynamic binding
  • Abstract class and methods
  • Interface
  • Abstract class vs interface
  • Encapsulation
  • Packages
  • Access modifiers
  • Garbage Collection
  • Inner classes
  • Static import
  • Static constructor

Java Exception Handling

  • Exception handling
  • Java try-catch
  • Java throw
  • Java throws
  • Checked and Unchecked Exceptions
  • Jav try catch finally
  • Exception Examples
  • Exception Propagation

Collections Framework

  • Collections in Java
  • Java ArrayList
  • Java LinkedList
  • Java Vector
  • Java HashSet
  • Java LinkedHashSet
  • Java TreeSet
  • Java HashMap
  • Java TreeMap
  • Java LinkedHashMap
  • Java Queue
  • Java PriorityQueue
  • Java Deque
  • Comparable interface
  • Comparator interface
  • Collections Interview Questions

MORE ...

  • Java Scanner Class
  • Java 8 Features
  • Java 9 Features
  • Java Conversion
  • Java Date
  • Java Multithreading
  • Java I/O
  • Java Serialization
  • Java Regex
  • Java AWT
  • Java Swing
  • Java Enum
  • Java Annotations
  • Java main method
  • Java Interview Q

Copyright © 2012 – 2025 BeginnersBook . Privacy Policy . Sitemap