1. this.x取内部类字段
2. Test.this.x 取外部类字段
/**
*
*/
package p_java;
import bsh.This;
public class Test {
public int x=10;
public class innerTest{
public int x=12;
public void getX(){
System.out.println(this.x);
System.out.println(Test.this.x);
}
}
public static void main(String[] args) {
Test test = new Test();
Test.innerTest innerTest=test.new innerTest();
innerTest.getX();
}
}
结果
12
10