Inheritance in Java

In this blog explain what is Inheritance, How to use inheritance & Types of Inheritance.

Inheritance:-

An object of one class behaving as an object of another class. In Java, inheritance means creating new classes based on existing ones. Inheritance purpose is code re-usability.

class RBI
{
credit( )
debit( )
si( )
ci( )
}
class SBI extends RBI
{

}

There are two major classes namely Parent class or Super class or Base class and Child class or sub class or derived class. Java using extends keyword.

  • Single Inheritance
  • Multilevel Inheritance
  • Hierarchical Inheritance
  • Hybrid Inheritance
  • Multiple Inheritance

Java not Support the Multiple Inheritance.

Single Inheritance:-

* Single inheritance, Subclasses inherit the Parent class. example Ais Parent class and B is Child class.

Class A Parent class Class B is the derived class.

single

Multilevel Inheritance:-

Multilevel inheritance in Java is Type of Inheritance in which class that is already inherited by another class, inherites anthoer class.

multilevel

Hierarchical Inheritance:-

  Hierarchical inheritance is a type of inheritance in which a parent class can have multiple child classes. In other words, it is a type of inheritance in which a parent class serves as a base for multiple child classes, and each child class inherits properties and methods from the parent class.

types of inheritance in java5

Hybrid Inheritance:
It typically involves a mix of single inheritance, multiple inheritances, hierarchical inheritance, or multilevel inheritance. While hybrid inheritance provides flexibility, it can also introduce complexities and challenges.

hybird

Reference:-

www.javatpoint.com

chat.openai.com

programmerbay.com