public class Person
{
int x=7;
class Fun//定义的内部类
{
int x=8;
void fun()
{
int x=9;
System.out.println(x);
}
}
void show()
{
System.out.println(x);
}
}
class Demo{
public static void main (String[] aegs){
Person.Fun pp=new Person().new Fun() ;
pp.fun();
}
}
运行的结果是
9;
要访问内部变量用this.x;打印的是:8
要是用Person.this.x;打印的是:7;
要想调用show方法必须要得到外部类的实例对象。