Java Program to demonstrate multi level inheritance

Program

class GrandParent
{
	GrandParent()
	{
		System.out.println("This is class 'GrandParent'");
	}
	void show()
	{
		System.out.println("This is a method in GrandParent");
	}
}
class Parent extends GrandParent
{
	Parent()
	{
		System.out.println("This is class 'Parent'");
	}
	void fun()
	{
		System.out.println("This is a method in Parent");
	}
}
class Child extends Parent
{
	Child()
	{
		System.out.println("This is class 'Child'");
	}
}
public class MultiLevelInheritance
{
	public static void main(String[] args)
	{
		Child chObj = new Child();
		chObj.show();
		chObj.fun();
	}
}

Output

This is class 'GrandParent'
This is class 'Parent'
This is class 'Child'
This is a method in GrandParent
This is a method in Parent

Tags: