It is a concept in java which provide the re usability of the members of one class/object to another class/object. Inheritance term itself defines the property inheriting. In java we are working with class so here we are going to inherit the property of one class into another i.e we are reusing the unresticted members of one class into other class who is inheriting that class. Now before going into depth you need to understand two term
1> Super class / parent class / inherited class.
2> Sub class / child class / inheriting class.

Super class

In java super class is the parents class of all the class who is inheriting that class. By default Object class of lang package is the super class of all class. By inheriting the super class we are free to use all the unrestricted member into subclass for our own custom implementation. Like by extending predefined classes we are using predefined methods .

Sub class

Subclass is the child class and is inheriting the members of its super class. For inheriting any class we need to use the extends keyword so that JVM will understand that a class is being inherited by another class.
The class which is going to use extend keyword is known as sub-class. For ex-

class A { }                                             
public class B extends A { } 

Here in the above program class B is extending class A that means
B --> Subclass
A --> super class 
and by default A is extending Object class that means A is subclass for Object class. So here is the Hierarchy for the above program how it is inheriting each other.



So now according to inheriting classes we can categorize inheritance into six category

1.  Simple Inheritance
2.  Multiple Inheritance  ( Not supported In java )
3.  Multi-level Inheritance
4.  Hierarchical Inheritance
5.  Hybrid Inheritance
6.  Cyclic Inheritance

For details on the above types of inheritance follow click here !


1 comment:

Blog Archive

Ads 468x60px

.

Ads

.

Featured Posts

Popular Posts

Like Us On FaceBook

Total Pageviews

Online Members

Live Traffic