Inheritance is an important concept in Java and in Object-Oriented Programming. It allows one class to inherit the properties and behaviors of another class. This means that the child class can access everything that belongs to the parent class.

For example, think of a father and son. Everything that belongs to the father also belongs to the son, and the son can access it. In the same way, a child class can access the properties and behaviors of its parent class. We use the keyword "extends" to establish this relationship between classes.

look at this example so you can have more idea;

public class Employee {
int salary = 50000;
}
class Labour extends Employee{
int bonus=10000;

public static void main(String[] args) {
Labour l = new Labour();
System.out.println("Salary is " + l.salary);
System.out.println("Bonus is " + l.bonus);

}

The Output:

                     Salary is 50000

                     Bonus is 10000

In above example Employee class is Parent class. and Labour is Child class: that inherits the Employee class. And also you can see we create a relationship with those two classes  using extends keyword.

The parent class is also called the super class, and the child class is also called the sub class. The parent class gives its properties and behaviors to the child class so that it can inherit and use them.


Here are some common uses of inheritance in Java:

1.Code Reusability:

Inheritance allows us to reuse code that already exists in a parent class. We can create a parent class with common properties and methods, and then have child classes inherit from that parent class. This way, we don't have to write the same code again and again for every child class.

2.Polymorphism:

Inheritance allows us to create objects that can take on different forms. This is known as polymorphism. We can have a variable of a parent class type that can refer to objects of child classes. This allows us to write more generic code that can work with different types of objects.

3.Method Overriding:

Inheritance allows us to override methods of the parent class in the child class. This means that we can provide a different implementation of a method in the child class. This is useful when we want to customize the behavior of a method for a specific child class.

4.Class Hierarchy:


Inheritance allows us to create a hierarchy of classes, where child classes inherit properties and methods from parent classes. This helps us to organize our code better and make it more understandable.



* Uses of Inheritance in java are from ChatGPT