外部类.this.成员域
在一个类的内部类中,如果需要访问外部类的方法或者成员域的时候,如果使用 this.成员域(与 内部类.this.成员域 没有分别) 调用的显然是内部类的域 , 如果我们想要访问外部类的域的时候,就要必须使用 外部类.this.成员域
public class TestA
{
public void tn()
{
System.out.println("外部类tn");
}
Thread thread = new Thread(){
public void tn(){System.out.println("inner tn");}
public void run(){
System.out.println("内部类run");
TestA.this.tn();//调用外部类的tn方法。
this.tn();//调用内部类的tn方法
}
};
public static void main(String aaa[])
{new TestA().thread.start();}
}

浙公网安备 33010602011771号