Implementation of Multilevel Inheritance using ‘java’
Multilevel inheritance is a feature found in some
object-oriented programming languages where a class can inherit properties and
behaviors from another derived class. In multilevel inheritance, a derived
class (also known as a subclass or child class) can inherit from a base class,
and another class can inherit from this derived class, forming a hierarchy of
classes.
In multilevel inheritance, each derived class inherits
the properties and behaviors of its immediate parent class. This allows for a
chain of inheritance, where each class adds its own characteristics while
building upon the features inherited from the previous class.
Program:-
class A
{
void showA()
{
System.out.println("Method A");
}
}
class B extends A
{
void showB()
{
System.out.println("Method B");
}
}
class C extends B
{
void showC()
{
System.out.println("Method C");
}
}
class MultiLevel
{
public static void main(String[] args)
{
C c1=new C();
c1.showC();
c1.showB();
c1.showA();
}
}
Output:
0 Comments