What is Inheritance in Java?

Inheritance is one of the features of Object Oriented Programming(OOPs). It is a mechanism in which an object acquires all the properties of its parent object. Inheritance allows one class to use variables and methods of other class.The derived class is called subclass and the base class is called as super-class. The derived class can have its own variables and methods.

Inheritance represents the IS-A relationship, also known as parent-child relationship.
Inheritance is a compile-time mechanism. A super-class can have any number of sub classes. But a subclass can have only one super-class. This is because Java does not support multiple inheritance.

Syntax:

class Subclass-name extends Superclass-name  
{  
   //methods and fields  
}  

The extends keyword indicates that you are making a new class that derives from an existing class. The meaning of "extends" is to increase the functionality.

Types of inheritance in java:

Java has 3 types of inheritance
  1. Single
  2. Multilevel
  3. Hierarchical













No comments:

Post a Comment