3
abstract class Two {
Two() {
System.out.println("Two()");
}
Two(String s) {
System.out.println("Two(String");
}
abstract int display();
}
class One {
public Two two(String s) {
return new Two() {
public int display() {
System.out.println("display()");
return 1;
}
};
}
}
class Ajay {
public static void main(String ...strings){
One one=new One();
Two two=one.two("ajay");
System.out.println(two.display());
}
}
我們不能實例化一個抽象類,那麼爲什麼是功能二兩(String s)將能夠創建抽象類兩個的實例????抽象類和匿名類
[停止預讀我的思想](http://stackoverflow.com/questions/5154740/abstract-class-and-anonymous-class/5154764#5154764)! – 2011-03-01 12:55:08
有沒有辦法讓MyTwo Anonymous? – 2011-08-25 14:37:40
@Usman是的,這就是原始海報的問題所在。 – 2011-08-26 07:28:10