Home » Core Java » Inheritance in Java

Inheritance in Java

 

What is Inheritance ?

1.  Inheritance is one of the main Object Oriented Programmings (OOPs) concept in java.

2. Inheritance is the process by which one class receive or inherits the properties of another class.The class which inherits the properties is called sub class or child class or derived class  and the class from which the properties are inherited is called super class or parent class or base class.Here by properties we mean methods and variables of the class.

3. Inheritance represents the IS-A relationship, also known as parent-child relationship.Suppose Animal  is a super class  and Dog is a sub class .So Dog is an(IS-A) animal.

4. We use extends keyword to represent inheritance relationship.

5. Using inheritance we can re use the code used in parent class

Type of Inheritance ::

There are 5 types of inheritance.But Multiple inheritance is not allowed in Java.Let us see examples of each inheritance type.

1. Single inheritance
2. Multi-level inheritance
3. Multiple inheritance(Java does not support)
4. Multipath inheritance
5. Hierarchical inheritance
6. Hybrid inheritance

Single Inheritance

Output ::

 


Leave a comment

Your email address will not be published. Required fields are marked *

17 − fourteen =