Java Inheritance

Level : Intermediate
Mentor: Shailendra Chauhan
Duration : 00:02:00

What is Inheritance in Java?

In Java, inheritance is used to create a new class that can be developed with the help of an existing class. This method allows a class to inherit from an existing one by reusing its methods and fields.

Important Terms Used in Java Inheritance

  • Class
  • Superclass/Parent Class
  • Subclass/Child Class
  • Reusability

Types of Inheritance in Java

There are 5 types of Inheritance in Java:

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

1. Single Inheritance

The term "single inheritance" refers to an inheritance wherein a single base class gives rise to one derived class.

2. Multilevel Inheritance

A derived class that participates in multilevel inheritance will inherit a base class, and it will also serve as the base class for subsequent classes.

3. Hierarchical Inheritance

In Java, hierarchical inheritance refers to a type of inheritance in which numerous child classes extend a single-parent class. Each child class inherits the parent class's attributes and methods while also defining its unique characteristics.

4. Multiple Inheritance

Multiple inheritance is an aspect of object-oriented concepts that allows a class to inherit properties from more than one parent class. 

5. Hybrid Inheritance

In Java, hybrid inheritance refers to when a class derives from multiple classes by combining different inheritance types. When a class uses hybrid inheritance, it can derive from a wide range of classes, some of which originated through interface inheritance and others through class inheritance.

Java is-a relationship

In Java, inheritance represents an is-a relationship. Inheritance can only be used when two classes have an is-a relationship. 

Method Overriding in Java Inheritance

In Java, method overriding occurs when you redefine any base class method with the same signature, that is, the same return type, number, and type of parameters in the derived class. In this case, the subclass method overrides the superclass method.

Self-paced Membership
  • 24+ Video Courses
  • 825+ Hands-On Labs
  • 400+ Quick Notes
  • 125+ Skill Tests
  • 10+ Interview Q&A Courses
  • 10+ Real-world Projects
  • Career Coaching Sessions
  • Email Support
Upto 60% OFF
Know More
Still have some questions? Let's discuss.
CONTACT US
Accept cookies & close this