Java Inheritance


Inheritance is the process where one class acquires some or all the properties (methods and fields) of another class.

Inheritance defines IS-A relationship between a super class and its sub class, also known as parent-child relationship.

Inheritance is used for code reusability and method overriding, so that runtime polymorphism can be achieved.

Syntax:

class SubclassName extends SuperclassName  
{
	// methods and fields  
}

Terms used in Inheritence

  • class: It is a template from which any number of objects can be created which have common properties.
  • Sub class/Child class: It is a class which inherits the properties (fields and methods) from other class. It is also called as a derived class, extended class or child class.
  • Super class/Parent class: It is the class from where a subclass inherits the properties (fields and methods). It is also called as a base class or a parent class.
  • Extends keyword: It is used to indicate that we are making a new class (sub class) that is deriving from an already existing class (super class).