//to demonstrate multi-level Inheritance and constructor chaining
class Inheritance
{
int x,y;
Inheritance(int a,int b)
{
/*here the compiler places the call
super(); automatically at compile time which is a call
to the ultimate super class i.e the Object class
*/
x=a;
y=b;
}
}
class sub1 extends Inheritance
{
int z;
sub1(int x,int y,int w)
{
super(x,y);// call to the super class constructor i.e calls the constructor of the Inheritance class
z=w;
}
}
class sub2 extends sub1
{
int a,b,c;
sub2(int x,int y,int w,int p,int q,int r)
{
super(x,y,w);// calling the constructor of the sub1 class
a=p;
b=q;
c=r;
}
}
class Test
{
public static void main(String args[])
{
sub2 obj=new sub2(10,20,30,40,50,60);
int x=obj.x;
System.out.println("the value is = "+x);
}
}