Multilevel Inheritance in Java
Multilevel Inheritance is said to have taken place when a child class inherits from a parent class and then child class becomes the parent class for another class. This process can do on and on. For example, if class B inherits class A, then class C inherits from class B and similarly class D inherits from class C. Then class D may or may not use the members of all the previous classes.
A Sample Program showing Multilevel Inheritance
class Baby
{
void eat()
{
System.out.println("eating...");
}
}
class Sleep extends Baby
{
void dream()
{
System.out.println("dreaming...");
}
}
class Walk extends Sleep
{
void talk()
{
System.out.println("talking...");
}
}
class Check
{
public static void main(String args[])
{
Walk d=new Walk();
d.talk();
d.dream();
d.eat();
}
}
Program Output
Download Source code of Baby program
share on : :
Love to hear your Views / Guidance / Recommendations on this Post…