Programming in Java
Object Oriented in Java
Advanced topics in Java
Modal Box
Tutorials
Inheritance in java
Inheritance we can say is the (super-sub) or (parent-child) or (base-derived) class relationship.
Inheritance is the main feature of object oriented programming through which the sub class inherits the features of its base class.
Types of Inheritance
1. Single Inheritance :
If a class inherits the features of another class, then it is known as single inheritance.
In java, a class inherits another class with the keyword ‘extends’.
class A { int i; }
class B extends A //how class inherits another class. { int j; // now this class automatically has i inherited variable. }
2. Hierarchical Inheritance :
In this type of inheritance, multiple classes inherit the same class.
class A { } class B extends A { } class C extends A { }
3. Multilevel Inheritance :
Multilevel inheritance can be understand with the below example.
class A { } class B extends A { } class C extends B { }
In the above example, class C inherits A but not directly, it inherits through B class.
Video/ C Introduction
Watch video in full size