请问如何访问外部类中的类
我是这样写的:public class Father {
String name = "zhangjun";
class Child {
public void introFather() {
System.out.println(Father.this.name);
}
}
}
class Test {
public static void main(String[] args) {
Child outting = new Father().new Child();
outting.introFather();
}
}
但提示:
Father.java:13: 错误: 找不到符号
Child outting = new Father().new Child();
^
符号: 类 Child
位置: 类 Test public class Father {
String name = "zhangjun";
class Child {
public void introFather() {
System.out.println(Father.this.name);
}
}
}
class Test {
public static void main(String[] args) {
Father.Child outting = new Father().new Child(); // 这里的类型应该是 Father.Child
outting.introFather();
}
}
页:
[1]