Java Inheritance | Types of Inheritance | Extends Class with Examples

 Java Inheritance is the concept of Object-Oriented Programming (OOPs). Where an Object (class or Interface) acquires the property(Methods, Variables, etc) of another object. It’s also called as Java extends the class.

So the idea behind this concept is the usability of code, which means when you create a new class (child class). This class extends another class (Parent class) and reuse methods, variables, and fields of the parent class. So you don’t need to write the same code again and again.

Java Inheritance Types of Inheritance Extends Class with Examples

Inheritance represents the IS-A relationship or can call a parent-child relationship. This Tutorial you will learn all about inheritance with how-to class and interfaces use on different types of Inheritance in Java.

Types of inheritance in Java

Here are 5 types of Inheritance we will learn with an example of this tutorial.

  1. Single Inheritance:
  2. Multiple Inheritance:
  3. Multilevel Inheritance
  4. Hierarchical Inheritance:
  5. Hybrid Inheritance:


The keyword used extends (for class) and Implements (for Interface) in Java Inheritance.

For class extends keyword

For Interface implements keyword

Important Terms in Inheritance

  • Class: class is the blueprint of an object, which has a common property.
  • Extends: extends is used to achieve Inheritance in SubClass.
  • Implements: implements comes when you want Inherit Interface.

Let’s start to Learn Java inheritance and Build examples

Java Inheritance and its Types with examples

If looking as class bases Inheritance there are three types of Inheritance – single, multilevel and hierarchical.

And about multiple and hybrid inheritance is supported through interface only in Java.

Single Inheritance

Example of Single Inheritance in Java with code

A Single Inheritance is a basic inheritance, where one class (subClass) inherits the features of one another class (superClass). Here is an example of Single Inheritance in Java with code.

Output: Running
2 Wheeler

Multilevel Inheritance

Example of Multilevel Inheritance in Java

The Multiple Inheritance Concept is very required to understand  Inheritance. So In this time, one class inherits Another one class and this class inherits Another one class property or features.

Grandfather -> Parent -> child

Let’s check this example of Multilevel Inheritance in Java.

Output: Running
2 Wheeler
Fuel Required: Petrol

Hierarchical Inheritance

Example code of Hierarchical Inheritance in Java

When a many class (subclass) inherit the common property of another class (Superclass), is called Hierarchical Inheritance.

Here is an example code of Hierarchical Inheritance in Java.

Output: Running
4 Wheeler
2 Wheeler

Multiple Inheritance

Where a class (child class)  inherits properties of more than one class (parent class) is called Multiple Inheritance. But it not supported in Java.

Java Multiple Inheritance is supported by interfaces. So by definition single Inheritance can inherit multiple Interface.

How to Multiple Inheritance in Java using an interface example.

Hybrid Inheritance

How Hybrid Inheritance in Java

As per the upper image you can see how Hybrid Inheritance in Java can implement. From Level 1 to 2 is easy but when it’s come to level 3 (Class D). That time you have to know Java not support an Inherit a single class inherit the property of many classes. Do get it done you have to use an Interface.

QA: Why use inheritance in Java?

This is an important question in Interview, it can also be called “What is the advantage of Inheritance in Java”?

Here are some reasons why use it:-

  • Most Important is code Usability.
  • Efficient to use, while writing code can increase the project development speed.
  • In OOPs concept – For Method Overriding
  • Make global changes to derived (child) classes by changing a base (parent) class.

QA: Why Multiple Inheritances are not supported in Java?

The problem with multiple inheritances is that two classes may define methods that have different ways of doing the same thing, and the subclass can’t choose which one to pick. It’s called the data ambiguity in Programming terms.

Here is an example if you did Multiple inheritances, then the compiler will throw an error.

multiple inheritance not supported java compiler time error

Do comment if you have any doubts and suggestions on this tutorial. This tutorial is targeted to java beginners.

Note: This example (Project) is developed in IntelliJ IDEA 2018.2.6 (Community Edition)
JRE: 11.0.1
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.14.1

Java version 11

All  Inheritance in Java with example programs PDF are in Java 11, so it may change on different from Java 9 or 10 or upgraded versions.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.