Java program to show the concept of multilevel inheritance

Multilevel inheritance

Multilevel inheritance means derive a class from base class which itself has been derived from another class.

eg.

We may have a base class called l1 from which we derive a class called l2 then we may derive a one more class from l1.

Picture Repersentation of Program

multilevel inheritance

In this program we have a base class called “base” from which we derive a class “derived1” and then we derive a another class “scan” from “derived1” class.We have made a object of class scan i.e. “d1” and from object “d1” we have called all the three functions of different classes.

import java.util.*;
class base
{
		
public void bdisplay()
{
   System.out.println("This is base class");
}
}
class derived1 extends base
{

	public void ddisplay()
	{
		System.out.println("This is derived1 class");
	
    }
 
}
class scan extends derived1
{
 public void sdisplay()
 {
	 System.out.println("This is scan class");
 }
 public static void main(String arg[])
{
 scan d1=new scan();
 d1.bdisplay();
 d1.ddisplay();
 d1.sdisplay();
}

}

OUTPUT

multilevel inheritance

Leave a Reply

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