Inheritance Types (Cont.)


Multilevel Inheritance
In multilevel inheritance, a derived class will be inheriting a base class and as well as the derived class also acts as the base class to other class. In the figure below, the class A serves as a base class for the derived class B, which in turn serves as a base class for the derived class C.

Multilevel.java (multilevel inheritance)
// Multilevel inheritance 
// Driver class
public class Multilevel {
  public static void main( String[ ] args ) {
    C c1 = new C( );
    c1.printName( args[0] );
    c1.printFor ( );
    c1.printName( args[0] );
  }
}
class A { 
  public void printName( String name ) { 
    System.out.print( name ); 
  } 
} 
class B extends A { 
  public void printFor( ) { 
    System.out.print( " for " ); 
  } 
}
class C extends B {
  public void printName( String name ) {
    super.printName( name );
  }
}
shell> java Multilevel    ⇒  Output:

      Result:

Important Facts about Inheritance (Cont.)



      My wife accused me of being immature.    
      I told her to get out of my fort.