/*
为什么内部类能直接访问外部类中的成员?
那是因为内部类持有了外部类的引用。 外部类名.this
*/
class Outer2
{
int num = 3;
class Inner2
{
int num = 4;
void show()
{
int num = 5;
System.out.println(Outer2.this.num);
}
}
void method()
{
new Inner2().show();
}
}
public class InnerClassDemo2 {
public static void main(String[] args) {
// TODO Auto-generated method stub
new Outer2().method();
}
}

被折叠的 条评论
为什么被折叠?



