Inheritance in java

Inheritance

It creates new classes using existing classes. So that the new classes will acquire all the feature of the existing classes is called Inheritance.

Syntax
class sub-classname extends superclass-name
{
//methods & statements;
}

Types of Inheritance

  • Single Inheritance

Producing sub classes from single super class is called single inheritance.

Untitled

Single Inheritance.

  • Multilevel Inheritance

In Multilevel Inheritance a sub class will be inheriting a super class and as well as the sub class act as the super class to other class.

UntitledMultilevel Inheritance.

  • Multiple Inheritance

Producing sub classes from multiple super classes is called multiple inheritance.

UntitledMultiple Inheritance.


Note

Multiple inheritance is not available in java.


  • Hierarchical Inheritance

Producing many sub classes from single super class is called hierarchical inheritance.

UntitledHierarchical Inheritance.

  • Hybrid Inheritance

Hybrid Inheritance is the combination of Single and Multiple Inheritance.Hybrid inheritance is also not supported in java.

UntitledHybrid Inheritance.


Why multiple inheritance is not available in java?

It leads to confusion for a java program. To reduce the complexity and simplify the language, multiple inheritance is not available in java.
The programmer can achieve multiple inheritance using interfaces.


 

Leave a Reply

Your email address will not be published. Required fields are marked *