日期:2014-05-20  浏览次数:20771 次

为什么这段代码能正常运行?
package test;

abstract class Base {
public Base(int i){
System.out.println("base construction, i="+i);
}
public abstract void f();
}
public class AnonymousConstruction{
public static Base getBase(int i){
System.out.print("anonymouys class");//抽象类不是不能被实例化的吗?为什么能这么实例化?
return new Base(i){
@Override
public void f() {

}

};
}

public static void main(String [] args){
Base base = getBase(47);
base.f();
}
}



------解决方案--------------------
Java code

new Base(i){
@Override
public void f() {

}

};