Using Anonymous Inner Classes to implement an interface - Java Object Oriented Design

Java examples for Object Oriented Design:interface

Description

Using Anonymous Inner Classes to implement an interface

Demo Code

public class AnonClass {
  public static void main(String[] args) {
    Ball b = new Ball() {
      public void hit() {
        System.out.println("You hit it!");
      }/*from ww w . j  a v a2  s  . c  o  m*/
    };
    b.hit();
  }

}

interface Ball {
  void hit();
}

Related Tutorials