# // Creating a constructor for an anonymous inner class.
# // From 'Thinking in Java, 3rd ed.' (c) Bruce Eckel 2002
# // www.BruceEckel.com. See copyright notice in CopyRight.txt.
# import com.bruceeckel.simpletest.*;
#
//其间认识到了以前理解上的 错误:抽象类是可以有构造函数的,并且仅仅是抽象类中的抽象方法不能有方法体
//在AnonymousConstructor类中定义内部类时,依然调用Base类中的构造函数
# abstract class Base {
# public Base(int i) { //匿名内部类是引用的外部定义的对象,编译器会要求其参数引用是final型(而本例中在getBase(int i)方法中的i不是final类型,是因为i没有在外部类base中使用)
# System.out.println("Base constructor, i = " + i);
# }
# public abstract void f();
# }
#
# public class AnonymousConstructor {
# private static Test monitor = new Test();
# public static Base getBase(int i) { //定义在静态方法中的内部类----匿名内部类---return new Base(i)类似于class Base{ Base(i)...的声明
# return new Base(i) {
# {
# System.out.println("Inside instance initializer");
# }
# public void f() {
# System.out.println("In anonymous f()");
# }
# }; //此处有个分号,表明表达式的结束
# }
# public static void main(String[] args) {
# Base base = getBase(47);
# base.f();
# monitor.expect(new String[] {
# "Base constructor, i = 47",
# "Inside instance initializer",
# "In anonymous f()"
# });
# }
# } ///:~