This
/*
this: 代表的是调用当前方法的对象
this可以使用对象中的成员变量,成员方法,构造方法
*/
class Test1{
int a = 10;
public void fun1(){
int a = 20;
//先在方法中寻找,若找不到去成员变量位置查找
//在一个方法中是无法访问另一个方法中定义的东西
System.out.println(a);
System.out.println(this.a); //获取当前对象中的成员变量a
this.fun2(); // 同一个类,方法内部可以调用该类中其它的方法
}
public void fun2(){
int a = 30;
System.out.println(a);
}
}
public class ThisDemo1 {
public static void main(String[] args) {
Test1 test1 = new Test1();
test1.fun1();
}
}