集册 Java实例教程 使用匿名内部类实现接口

使用匿名内部类实现接口

欢马劈雪     最近更新时间:2020-01-02 10:19:05

442
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
使用匿名内部类实现接口

public class AnonClass {
/* 
 来自 
*时代Java - nowjava.com*/

  public static void main(String[] args) {

    Ball b = new Ball() {

      public void hit() {

        System.out.println("You hit it!");

      }

    };

    b.hit();

  }


}

/*
 from N o w J a v a . c o m 
*/

interface Ball {

  void hit();

}