5.面试题public class Outer {
public void someOuterMethod() {
// Line 3
}
public class Inner {
}
public static void main(String[] argv) {
Outer o= new Outer();
// Line 8
}
}
/*
* Which instantiates an instance of Inner?
A. new Inner(); // At line 3
B. new Inner(); // At line 8
C. new o.Inner(); // At line 8
D. new Outer.Inner(); // At line 8
*/
答案A.new Inner();等价于this.new Inner();已经存在一个Outer类对象了.
line 8 正确写法,应为: o.new Inner();