Sunday 13 September 2015

Java - Inheritance

Java - Inheritance

Java Inheritance can be defined as the process where one class acquires the properties (methods and fields) of another. With the use of inheritance the information is made manageable in a hierarchical order.
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).

extends Keyword

extends is the keyword used to inherit the properties of a class. Below given is the syntax of extends keyword in Java .
class Super{
.....
.....
}

class Sub extends Super{
.....
.....

}  

The super keyword

The super keyword is similar to this keyword following are the scenarios where the super keyword is used.
  • It is used to differentiate the members of superclass from the members of subclass, if they have same names.
  • It is used to invoke the superclass constructor from subclass.

0 comments:

Post a Comment