Java Programming

6.7 Inheritance

Inheritance is one of the key features of Object Oriented Programming.
Inheritance provided mechanism that allowed a class to inherit property of another class. When a Class extends another class it inherits all non-private members including fields and methods.

The class which inherits the properties of other is known as subclass (derived class, child class) and the class whose properties are inherited is known as superclass (base class, parent class).

Inheritance defines is-a relationship between a Super class and its Sub class. extends and implements keywords are used to describe inheritance in Java.

Why use inheritance in java
-For Method Overriding (so runtime polymorphism can be achieved).
-For Code Reusability.

Syntax of Java Inheritance
class Subclass-name extends Superclass-name
{
//methods and fields
}

extends is the keyword used to inherit the properties of a class.

super keyword
In Java, super keyword is used to refer to immediate parent class of a class. In other words super keyword is used by a subclass whenever it need to refer to its immediate super class.

Download for more knowledge

https://play.google.com/store/apps/details?id=ab.java.programming

Leave a comment