/home/wpollock1/public_html/Java/AnonDemo.java

// Demonstration of a simple (if that's possible) use of an anonymous
// local class.  (Note that anonymous classes really do have names.  In
// this case, the class gets the name "AnonDemo$1".)
//
// Written 11/25/2014 by Wayne Pollock, Tampa Florida USA

/** Class Greet is a simple class with one method, that displays a greeting:
*/
class Greet {
  public void sayHello( String name ) {
     System.out.println( "Hello, " + name + "!" );
  }
}

class AnonDemo {
   public static void main ( String[] args ) {

      // Create a Greet object, and invoke its method:
      Greet g = new Greet();
      g.sayHello( "Jordan" );

      // Create an object of an anonymous class that extends class Greet,
      // and overrides the sayHello method to say "Good Night" instead:
      Greet gn = new Greet() {
         public void sayHello( String name ) {
            System.out.println( "Good night, " + name + "." );
         }
      };
      gn.sayHello( "Wayne" );
   }
}