By: Jatin Chawla
Java Inheritance is one of the key concept of OOP language that enables us to arrange the classes in hierarchical form / tree structure just like a child / baby inherit the characteristics of his parents and develop new characteristics of his / her own. In similar way, in Java a programmer can write a new class that can adopt / inherit the accessible (type modifier) fields and methods of existing class and can include new attributes. It allows us to easily reuse code and extend the functionality of existing class.
Definition: The inclusion of members of the existing class in a new class so that they are accessible in the new class is known as INHERITANCE.
Using this aspect of OOP, we can create a new class from the already existing class. We can extends the functionality of the old class in the way that suit our current need. The television class can contain the subclasses such as B/W Television, Color Television and Home Theater style television. The new class is called Derived Class, Sub Class, Child Class; The existing (OLD) class that is being inherited is called as Super, Base, Parent Class. Once the super class has been written, tested and debugged; Its functionality can be reused by the sub class rather than being rewrite from the screen.
In Java, One class can be inherited from another by using "extends" keyword. A new class cannot be inherited from more than two class means one class cannot be a sub class of more than two classes
class sub_class_name extends super_class
{
Member 1;
Member 2;
}
There are three types of Inheritance:
- 1. Simple Inheritance: In this type of Inheritance, a single class is inherited all attributes from super class. e.g. Every person has a name and age, some persons may be student that have a roll no. and class i.e. Every student has a name ,age, roll no. and class.
- 2. Multilevel Inheritance: In this type of Inheritance, a single class is inherited all attributes from super class and the derived class further derive a new class and adopt all the features of that class. e.g. Every person has a name and age, some persons may be student that have a roll no. and class. Every student contain some subjects and their results then we organise all of them in a simple manner i.e. Every student has a name, age, roll no., class, subjects and their results.
- 3. Hierarchical Inheritance: In this type of Inheritance, a single class derives more than two classes. e.g. Every person has a name and age, some persons may be student that have a roll no. and class; And In other way every employee has a unique ID in his / her organisation and designation. Then we can say that every student has a name, age, roll no. and class and every employee has a name, age, ID, Designation.



Link to Us