首先,我理解的this就是指向当前对象。但是如下代码让人有点想不通。
//父类
public class Sup {
public Object f1 = "Sup.f1";
public Object f2 = "Sup.f2";
public void mA(){
System.out.println("Sup.mA");
}
public void mB(){
this.mA();
}
public void getF1(){
System.out.println(this.f1);
}
public void getF2(){
System.out.println(this.f2);
}
}
//子类
public class Sub extends Sup {
public Object f1 = "Sub.f1";
public Object f2 = "Sub.f2";
public void mA(){
System.out.println("Sub.mA");
}
public void getF2(){
System.out.println(this.f2);
}
}
//测试类
public class Test {
public static void main(String[] args) {
Sup sup1 = new Sub();
sup1.mB();
sup1.getF1();
sup1.getF2();
}
}