an example of a simple anonymous class : Anonymous class « Class « Java






an example of a simple anonymous class

    

public class MainClass {
  public static void main(String[] args) {
    Ball b = new Ball() {
      public void hit() {
        System.out.println("You hit it!");
      }
    };
    b.hit();
  }

  interface Ball {
    void hit();
  }
}

   
    
    
  








Related examples in the same category

1.Tick Tock with an Anonymous Class
2.Access inner class from outside
3.Anonymous inner class
4.This program demonstrates anonymous inner classes