Day-66 Types of Inheritance in Java

Inheritance is a powerful feature in Object-Oriented Programming (OOP) that allows a class to reuse the properties and methods of another class. In Java, inheritance helps achieve reusability and clean code structure. There are five types of inheritanc…


This content originally appeared on DEV Community and was authored by Tamilselvan K

Inheritance is a powerful feature in Object-Oriented Programming (OOP) that allows a class to reuse the properties and methods of another class. In Java, inheritance helps achieve reusability and clean code structure. There are five types of inheritance.

1. Single Inheritance

One child class inherits from one parent class.

   Parent
     ↓
   Child

2. Multilevel Inheritance

A class inherits from a class, which itself inherits from another class.

   GrandParent
        ↓
      Parent
        ↓
      Child

3. Hierarchical Inheritance

Multiple classes inherit from the same parent class.

         Parent
         /   \
     Child1  Child2

4. Hybrid Inheritance

Combines more than one type of inheritance (for example, multilevel + hierarchical).

       GrandParent
            ↓
         Parent
        /     \
   Child1    Child2

Java does not support hybrid inheritance using classes directly, because it can lead to ambiguity and confusion in method resolution.

5. Multiple Inheritance

A class attempts to inherit from more than one parent class.

    Parent1   Parent2
        \     /
         Child

Java does not support multiple inheritance with classes to avoid method conflict, commonly known as the Diamond Problem.

What is the Diamond Problem?

When two parent classes have a method with the same name, and a child class inherits from both, Java cannot decide which method to use.

       A
      / \
     B   C
      \ /
       D

This is called the Diamond Problem. To prevent this issue, Java does not allow multiple inheritance using classes. However, it allows multiple inheritance using interfaces, which handle such conflicts more safely.


This content originally appeared on DEV Community and was authored by Tamilselvan K


Print Share Comment Cite Upload Translate Updates
APA

Tamilselvan K | Sciencx (2025-07-26T06:36:08+00:00) Day-66 Types of Inheritance in Java. Retrieved from https://www.scien.cx/2025/07/26/day-66-types-of-inheritance-in-java/

MLA
" » Day-66 Types of Inheritance in Java." Tamilselvan K | Sciencx - Saturday July 26, 2025, https://www.scien.cx/2025/07/26/day-66-types-of-inheritance-in-java/
HARVARD
Tamilselvan K | Sciencx Saturday July 26, 2025 » Day-66 Types of Inheritance in Java., viewed ,<https://www.scien.cx/2025/07/26/day-66-types-of-inheritance-in-java/>
VANCOUVER
Tamilselvan K | Sciencx - » Day-66 Types of Inheritance in Java. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/07/26/day-66-types-of-inheritance-in-java/
CHICAGO
" » Day-66 Types of Inheritance in Java." Tamilselvan K | Sciencx - Accessed . https://www.scien.cx/2025/07/26/day-66-types-of-inheritance-in-java/
IEEE
" » Day-66 Types of Inheritance in Java." Tamilselvan K | Sciencx [Online]. Available: https://www.scien.cx/2025/07/26/day-66-types-of-inheritance-in-java/. [Accessed: ]
rf:citation
» Day-66 Types of Inheritance in Java | Tamilselvan K | Sciencx | https://www.scien.cx/2025/07/26/day-66-types-of-inheritance-in-java/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.