Java Tutorial: Inheritance in Java
Inheritance
It is a mechanism of getting new classNamefrom an old class
It retries all the attributes with its functionality
It reduces the retyping of a code and supports reusability
The new classNameis named as sub classNameand the old classNameis named as super class
To attain inheritance in java the keyword extends is employed
Types
Syntax
{`classNameold_class
{
}
classNamenew_classNameextends old_class
{
}
`}
Example
The underlying example specifies how an extends keyword is applied to attain inheritance mechanism in java
All forms of inheritance are implementable in java using extends keyword excluding multiple inheritance.
It highlights a single classNameis not extendable from multiple classes at a time
Hence the following syntax is not implementable
public classNamenew_classNameextends old_class_1 , old_class_2
{
}
Note: On the other hand, interface is employed to put into an action for the successful execution of multiple inheritance in java. It is clearly described in the chapter Interfaces