Before thinking about what inheritance is in Java, let’s see what inheritance is. Inheritance is nothing but the word that points to the characteristics or genetic traits from parents. In simple the children will get the facial features or characters from their parents, which is called Inheritance. In the next section, let’s see what inheritance is in Java.
What Is Inheritance in Java?
Similar to the genetic traits of humans to their children, Inheritance in Java is a fundamental concept of OOP(object-oriented programming) that allows a class to access the properties (fields) and behaviors (methods) of another class. This mechanism makes an “is-a” relationship between two classes. It helps code reusability and hierarchical structure in program design.
Key Inheritance concept in Java
- → Superclass: This class is basically called as Parent Class / Base Class, whose behaviors are inherited.
- → Subclass: This class is typically called a Child Class / Derived Class that inherits properties and behaviors from Parent Class, which is the Superclass.
- → extends Keyword: Used to make a connection between the classes. To inherit the properties and behaviors, we can use the extends Keyword.
Inheritance syntax in Java
// Parent class (also called the superclass)
class Animal {
void eat() {
System.out.println("This animal eats food.");
}
}
// Child class (also called the subclass)
class Dog extends Animal {
void bark() {
System.out.println("The dog barks.");
}
}
// Main class to test inheritance
public class InheritanceExample {
public static void main(String[] args) {
Dog d = new Dog();
d.eat(); // Inherited from Animal
d.bark(); // Defined in Dog
}
}
Finally, the main advantage of Inheritance in Java is code reusability and improved maintainability.
Why Is Inheritance Important in Java?
As we already know that inheritance is a fundamental concept in Java’s object-oriented programming (OOP) and offers several advantages, which are listed below:
- → Code Reusability: Inheritance allows a child class or subclass to use the properties and methods of its parent class or superclass. So, we don’t need to rewrite the same code again.
- → Improved Maintainability: When we define a common functionality in a parent class, any updates or fixes made there are automatically applied to all the subclasses or child classes. So, this makes code maintainability easier.
- → Method Overriding and Polymorphism: Inheritance is most important for achieving runtime polymorphism by overriding the method. Subclasses or child classes can provide their own specific methods inherited from the base or parent, or superclass. It allows objects of different subclasses or child classes to be called or treated uniformly through a common superclass or parent class reference.
- → Hierarchy and Organization: Inheritance helps to create a hierarchy of relationships between two classes. It reflects real-world “IS-A” relationships. For example: Parrot IS-A Bird. So, this improves the code organization and readability, also making the code easier to understand and manage.
- → Extension and Specialization: Subclasses or child classes can extend and specialize the functionality of their superclass. They can add new fields and methods or modify the inherited class based on their specific needs without making any changes to the superclass.
Inheritance real-time example in Java:
class Vehicle {
void start() { System.out.println("Vehicle starting..."); }
}
class Car extends Vehicle {
void openTrunk() { System.out.println("Trunk opened."); }
}
class Bike extends Vehicle {
void kickStart() { System.out.println("Bike kick-started."); }
}
The above use case explains that the vehicle contains common features for all vehicles (like start), while specific types (Car, Bike) extend it with their own behaviors.
Types of Inheritance in Java
Types of inheritance in Java with example
Since we already know that Inheritance is one of the most important concepts in object-oriented programming. From one class to another class, it allows us to use the properties and methods, and promotes code reusability and cleaner design. Let’s look into the different types of inheritance in Java.
There are different types of inheritance in Java, such as Single Inheritance, Multilevel Inheritance, Hierarchical Inheritance, and Hybrid Inheritance (which are achieved through interfaces). Java does not support Multiple Inheritance directly with classes to avoid ambiguity, but we can achieve it through interfaces. Below, we are going to see the types of Inheritance in Java:
Single Inheritance in Java
Single Inheritance in Java is the most common and basic form of inheritance. It happens when one child class inherits from another parent class. By this, the class will be able to access all the public and protected members of the parent class. So, it helps code reusability and better structure.
Example:
class Animal {
void breathe() {
System.out.println("All animals breathe to live.");
}
}
class Bird extends Animal {
void fly() {
System.out.println("Birds can fly high in the sky.");
}
}
public class SingleInheritanceExample2 {
public static void main(String[] args) {
Bird parrot = new Bird();
parrot.breathe(); // inherited from Animal
parrot.fly(); // defined in Bird
}
}
Output:
All animals breathe to live.
Birds can fly high in the sky.
Diagram of Single Inheritance in Java:

Multilevel Inheritance in Java
Multilevel inheritance in Java is nothing but it happens when a class is derived from another class, which is also derived from another class. Basically, it forms a chain of inheritance. In simple terms, the child class inherits the properties and methods from the parent class. And the parent class may itself be a child of another class. So, in this way, it helps code reusability and maintains a logical relationship between classes.
In simple terms, what is Multilevel Inheritance in Java? It means creating a hierarchy where each class builds upon the features of the class above it.
For Example:
class LivingBeing {
void breathe() {
System.out.println("All living beings breathe.");
}
}
class Animal extends LivingBeing {
void eat() {
System.out.println("Animals eat food to survive.");
}
}
class Dog extends Animal {
void bark() {
System.out.println("Dogs bark to communicate.");
}
}
public class MultilevelInheritanceExample {
public static void main(String[] args) {
Dog dog = new Dog();
dog.breathe(); // from LivingBeing
dog.eat(); // from Animal
dog.bark(); // from Dog
}
}
Output:
All living beings breathe.
Animals eat food to survive.
Dogs bark to communicate.
The above example clearly shows a multilevel inheritance program in Java, how properties and behaviors flow through multiple levels — from LivingBeing → Animal → Dog.
Diagram of Multilevel Inheritance in Java:

Hierarchical Inheritance in Java
Hierarchical inheritance in Java happens when multiple classes inherit from a single parent class. The parent class contains common properties or methods, while each child class can add its own behavior. This type of hierarchy inheritance in Java helps us in reducing code duplication and improving reusability.
Diagram of Hierarchical Inheritance in Java:

Here, both Bird and Fish inherit from the same parent class Animal.
Example of Hierarchical Inheritance in Java:
class Animal {
void eat() {
System.out.println("All animals eat food.");
}
}
class Bird extends Animal {
void fly() {
System.out.println("Birds can fly in the sky.");
}
}
class Fish extends Animal {
void swim() {
System.out.println("Fish swim in water.");
}
}
public class HierarchicalInheritanceExample {
public static void main(String[] args) {
Bird parrot = new Bird();
parrot.eat(); // inherited from Animal
parrot.fly();
Fish goldfish = new Fish();
goldfish.eat(); // inherited from Animal
goldfish.swim();
}
}
Output:
All animals eat food.
Birds can fly in the sky.
All animals eat food.
Fish swim in water.
This hierarchical inheritance example in Java shows how multiple subclasses can share common behavior from one parent class while defining their own unique features.
Hybrid Inheritance in Java
Hybrid inheritance in Java is a combination of two or more types of inheritance, such as single, multilevel, and hierarchical inheritance. It forms a complex relationship between classes where one class may inherit from multiple parent classes through interfaces.
However, Java does not support hybrid inheritance directly using classes because it can create ambiguity, especially if multiple parent classes have methods with the same name. To overcome this, Java uses interfaces to achieve hybrid inheritance safely.
Hybrid Inheritance in Java with Example:
interface Animal {
void eat();
}
class Mammal {
void walk() {
System.out.println("Mammals can walk.");
}
}
class Human extends Mammal implements Animal {
public void eat() {
System.out.println("Humans eat food to survive.");
}
void speak() {
System.out.println("Humans can speak languages.");
}
}
public class HybridInheritanceExample {
public static void main(String[] args) {
Human person = new Human();
person.eat(); // from Animal interface
person.walk(); // from Mammal class
person.speak(); // from Human class
}
}
Output:
Humans eat food to survive.
Mammals can walk.
Humans can speak languages.
This hybrid inheritance program in Java demonstrates how interfaces and classes can be combined to achieve hybrid inheritance safely, avoiding conflicts while ensuring code reusability.
Diagram of Hybrid Inheritance in Java:

Multiple Inheritance in Java (Using Interface)
In Java, multiple inheritance means that a class can inherit behavior from more than one parent. However, multiple inheritance in Java using classes is not allowed, because it can cause ambiguity if two parent classes have methods with the same name. To solve this problem safely, Java allows multiple inheritance using interfaces.
So, how can we achieve multiple inheritance in Java?
By implementing multiple interfaces in a single class using the implements keyword. This way, a class can inherit abstract methods from multiple sources and define them as needed.
Example of Multiple Inheritance in Java (Using Interface):
interface Engine {
void startEngine();
}
interface MusicSystem {
void playMusic();
}
class Car implements Engine, MusicSystem {
public void startEngine() {
System.out.println("Engine started.");
}
public void playMusic() {
System.out.println("Playing music...");
}
}
public class MultipleInheritanceExample {
public static void main(String[] args) {
Car myCar = new Car();
myCar.startEngine();
myCar.playMusic();
}
}
Output:
Engine started.
Playing music…
This multiple inheritance program in Java clearly shows how to achieve multiple inheritance in Java using interfaces. So, while multiple inheritance through classes is not possible, Java provides a clean and flexible way to implement it through interfaces.
Diagram of Multiple Inheritance in Java:

Why Multiple Inheritance Is Not Supported in Java?
Many beginners wonder, Why is multiple inheritance not supported in Java?
The answer lies in a problem called the Diamond Problem.
Let’s understand it simply. Suppose Class A has a method named show(). Now, Class B and Class C both inherit from A, and each overrides the show() method. If another Class D tries to inherit from both B and C, then Java faces confusion — which version of show() should D inherit? This is called the Diamond Problem in inheritance.
To avoid this ambiguity, multiple inheritance in Java through classes is not supported. So, which inheritance is not supported in Java? Multiple inheritance using classes.
Then, how does Java solve this?
Java provides interfaces to achieve multiple inheritance safely. When a class implements multiple interfaces, the compiler knows exactly which method to use because interfaces only declare methods — they don’t provide implementation. This removes ambiguity completely.And remember, the extends keyword is used to inherit a class in Java, while the implements keyword is used to inherit interfaces. Thus, multiple inheritance in Java is possible by using interfaces, ensuring clarity and clean design.
Constructor and Method Inheritance Concepts
When we talk about constructor in inheritance in Java, it’s important to note that constructors are not inherited. Unlike normal methods, a constructor belongs only to the class where it is defined. So, can we inherit a constructor in Java? No, but a child class can call the parent’s constructor using the super() keyword. This ensures that the parent part of the object is initialized before the child’s.
Now, let’s talk about static methods. Can we inherit static methods in Java? Technically, static methods belong to the class, not the object. They can be accessed by child classes, but they are not truly inherited or overridden; they are hidden, not redefined.
In inheritance and polymorphism in Java, constructors demonstrate how object creation flows through the hierarchy, while methods (especially overridden ones) show polymorphic behavior, meaning the same method name behaves differently depending on the object type. Together, they make Java’s object-oriented model powerful and predictable.
Real-Time Examples and Use Cases
Understanding inheritance in Java with a real-world example helps connect theory to real-world applications. Inheritance allows developers to reuse existing code efficiently, making it one of the most powerful OOP features in Java. Let’s look at some real-time examples of inheritance in Java that are commonly seen in projects.
Example 1: Employee–Manager Relationship
In a company system, you might have a base class called Employee that holds common details like name, ID, and salary. The Manager class extends Employee and adds extra features such as team handling or performance reviews. This is a real-time example of inheritance in Java, showing how shared attributes are reused while adding specific behavior.
Example 2: Vehicle–Car–Truck Hierarchy
In a transport management system, a Vehicle class may define speed and fuel capacity. The Car and Truck classes inherit these properties and add their own. This can be visualized in an inheritance in Java diagram, showing clear parent–child relationships.
In real-world projects, inheritance simplifies maintenance, promotes clean design, and ensures code reusability, essential for professional Java developers.
Common Interview Questions on Inheritance in Java
When preparing for interviews, understanding the core concept of inheritance in Java is essential. Employers often ask candidates to explain inheritance in Java, its advantages, and how it supports code reusability and scalability. You may also be asked to explain different types of inheritance in Java, such as single, multilevel, and hierarchical, along with examples. Some questions focus on inheritance and interfaces in Java, testing your understanding of how interfaces help achieve multiple inheritance. Practicing common inheritance questions in Java not only strengthens your technical foundation but also boosts your confidence during interviews. Below, we can see a few of the most Common Interview Questions on Inheritance in Java.
1. Types of inheritance and their Scope
· Single Inheritance: A class inherits from only one superclass.
· Multilevel Inheritance: A child class inherits from a parent class, which itself inherits from a grandparent class.
· Hierarchical Inheritance: Multiple classes inherit from a single parent class.
· Multiple Inheritance (through interfaces): Java does not support multiple inheritance with classes (to avoid complexity and ambiguity, e.g., the Diamond Problem). However, a class can implement multiple interfaces, inheriting behavior from multiple sources.
· Hybrid Inheritance (through interfaces): A combination of multiple inheritance types. In Java, hybrid inheritance is achieved using interfaces because Java does not support multiple inheritance with classes.
2. How do we achieve multiple inheritance using interfaces in Java?
· Java doesn’t support multiple inheritance with classes, but we can achieve it using interfaces.
· A single class can implement multiple interfaces, combining behaviors from different contracts without the complexity of multiple class inheritance.
3. How we declare multiple inheritance using interfaces in Java? If we wanted to implement multiple interfaces? how?
· class Class1 implements Interface1, Interface2, Interface3 {}
4. Can a class extend itself? No, a class in Java cannot extend itself. Trying to do so causes a compilation error.
5. Why is multiple inheritance not possible in Java? Java doesn’t support multiple inheritance with classes to avoid ambiguity error and conflicts, especially when two parent classes have the same method, leading to confusion for the compiler about which method to execute.
6. What is the diamond problem in Java, and how does Java address it?
· The diamond problem happens when two classes (Class B and class C) both inherit from a common superclass (class A).
· A third class (class D) inherits both of those classes (Class B and class C).
· Now, if the common superclass has a method, there’s a conflict: which version should the child inherit?
· Java handles this by not allowing multiple inheritance with classes, and resolving conflicts using default methods in interfaces.
7. How do default methods in interfaces resolve the diamond problem?
· If two interfaces have the same default method, the class that implements them must override that method to avoid ambiguity — giving control back to the developer.· To resolve it, the class must override the method and provide its own implementation — so the developer has full control.
Conclusion
Inheritance in Java is one of the core pillars of object-oriented programming that helps developers build scalable, reusable, and maintainable applications. Through this blog, we explored what inheritance is in Java, different types of inheritance, and real-time examples that show how it is applied in practical software development. We also looked at multiple inheritance, interfaces, constructors, and interview questions — everything you need to master the concept confidently.
If you’re looking to crack your first Java interview or start a strong IT career, Payilagam is here to guide you. Our Java Full Stack Training in Chennai helps you learn by doing — from core Java and inheritance concepts to building real-world applications.
Take the next step in your career with Payilagam. Join the Java Full Stack Training in Chennai today and get job-ready!
