document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. //to demonstrate multi-level Inheritance and constructor chaining
  2. class Inheritance
  3. {
  4.     int x,y;
  5.     Inheritance(int a,int b)
  6.     {
  7.         /*here the compiler places the call
  8.           super(); automatically at compile time which is a call
  9.           to the ultimate super class i.e the Object class
  10.           */
  11.         x=a;
  12.         y=b;
  13.     }
  14.    
  15. }
  16.  
  17. class sub1 extends Inheritance
  18. {
  19.     int z;
  20.     sub1(int x,int y,int w)
  21.     {
  22.         super(x,y);// call to the super class constructor i.e calls the constructor of the Inheritance class
  23.         z=w;
  24.     }
  25. }
  26.  
  27. class sub2 extends sub1
  28. {
  29.     int a,b,c;
  30.     sub2(int x,int y,int w,int p,int q,int r)
  31.     {
  32.         super(x,y,w);// calling the constructor of the sub1 class
  33.         a=p;
  34.         b=q;
  35.         c=r;
  36.     }
  37.        
  38. }
  39.  
  40. class Test
  41. {
  42.     public static void main(String args[])
  43.     {
  44.         sub2 obj=new sub2(10,20,30,40,50,60);
  45.         int x=obj.x;
  46.         System.out.println("the value is = "+x);
  47.     }
  48. }
');