Thursday 24 April 2014

Multi Level Inheritance

The method of deriving a class from another derived class is called as multilevel inheritance. C derived from B. and B derived from A.


Example
class A{

   A(){
      System.out.println("I am class A's default constructor");
   }
 
   A(int a){
      System.out.println("I am class A's parameterized constructor");
   }

}

class B extends A{

   B(){
      System.out.println("I am class B's default constructor");
   }
 
   B(int a){
      System.out.println("I am class B's parameterized constructor");
   }

}

class C extends B{
   C(){
      System.out.println("I am class C's default constructor");
   }
 
   C(int a){
      System.out.println("I am class C's parameterized constructor");
   }
 
   public static void main(String args[]){
      new C();
      new C(10);
   }
}



Prevoius                                                 Next                                                 Home

No comments:

Post a Comment