Java Multilevel inheritance

Multi level inheritance is a Derived class is Base class of another class. In below example class B is derived from A, and B is further base class of C.

One of the point to ponder in Multilevel inheritance is, what is the order in which constructors are invoked. First Base most constructor gets invoked, and then its Derived constructor, and so on. In below example, when an object of C is created, first constructor of class A gets invoked, then constructor of class B, finally class C constructor is invoked.

To understand this keyword, please refer Usage of this keyword

class A{
	int i;
	public A(int i)
	{
		this.i = i;
		System.out.println("A(int i)");
	}

	public void show()
	{
		System.out.println("Value of i is:"+i);
	}
}

class B extends A{
	int j;
	public B(int i,int j)
	{
		super(i);
		this.j = j;
		System.out.println("B(int i,int j)");
	}
	public void show()
	{
		super.show();
		System.out.println("Value of j is:"+j);
	}
}

class C extends B{
	int k;
	public C(int i,int j,int k)
	{
		super(i,j);
		this.k = k;
		System.out.println("C(int i,int j,int k)");
	}

	public void show()
	{
		super.show();
		System.out.println("Value of k is:"+k);
	}
}

public class MultiLevelInheritance {

	public static void main(String[] args) {
		C obj = new C(10,20,30);
		obj.show();
	}

}

You may also like to read: Hierarchical Inheritance