/*
为什么内部类能直接访问外部类中的成员?
那是因为内部类持有了外部类的引用。 外部类名.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();
}
}
内部类----细节
最新推荐文章于 2023-03-15 23:28:41 发布