Interfaces (Cont.)


Why Interfaces? An Interface Example

InterfaceDemo.java (interfaces)
// Demonstration of how interface works
// A simple interface 
interface in1 { 
  final int a = 10;             // public, static, and final 
  void display( String arg );   // public and abstract
}

// A class implements the interface. 
class InterfaceDemo implements in1 { 
  // Driver Code
  public static void main ( String[ ] args ) {
    InterfaceDemo i = new InterfaceDemo( );
    i.display( args[0] );
    System.out.print( " " + a );
  }
  // Implementing the capabilities of interface 
  public void display( String arg ) { System.out.print( arg ); } 
}
shell> java InterfaceDemo    

Output:           Result:




      If you bite off more than you can chew (exceed your limit),    
      you set yourself up to fail.