java子类父类的this相同吗
class A{ public String TAG="TAGA"; public String c="---C"; public A(){ Log.i(TAG, "A: "+this+this.TAG+this.c); this.funA1(); } public void funA1(){ Log.i(TAG, "funA1: "); } } class B extends A{ public String TAG="TAGB"; public B(){ super(); Log.i(TAG, "B: "+this+this.TAG+this.c); this.funA1(); } @Override public void funA1() { Log.i(TAG, "funA1: "); super.funA1(); } public static void main(String[] args) { new B(); } }
2022-02-20 19:22:19.664 13648-13764/com.example.bottomnavigationactivityapp I/TAGA: A: com.example.bottomnavigationactivityapp.B@efc6238TAGA---C
2022-02-20 19:22:19.664 13648-13764/com.example.bottomnavigationactivityapp I/TAGA: funA1:
2022-02-20 19:22:19.664 13648-13764/com.example.bottomnavigationactivityapp I/TAGB: B: com.example.bottomnavigationactivityapp.B@efc6238TAGB---C
2022-02-20 19:22:19.664 13648-13764/com.example.bottomnavigationactivityapp I/TAGB: funA1:
2022-02-20 19:22:19.664 13648-13764/com.example.bottomnavigationactivityapp I/TAGA: funA1:
---------
class A{ public String TAG="TAGA"; public String c="---C"; public A(){ System.out.println(TAG+ "\t"+"A: "+this+this.TAG+this.c); // 1 this.funA1(); } public void funA1(){ System.out.println(TAG+"\t"+"funA1: "); // 2 } } public class B extends A{ public String TAG="TAGB"; public B(){ super(); System.out.println(TAG +"\t"+ "B: "+this+"\t"+this.TAG+"\t"+this.c); this.funA1(); } @Override public void funA1() { System.out.println(TAG+ "\t"+"funA1: "); // 2 被A构造方法this.funA1();调用,但是B构造方法初始化A的时候呀,A还没初始化完成,导致B的成员变量TAG还没初始化,所以 TAG 为null super.funA1(); } public static void main(String[] args) { new B(); } } //TAGA A: com.java.sjq.base.classInitOrder.B@77468bd9TAGA---C //null funA1: //TAGA funA1: //TAGB B: com.java.sjq.base.classInitOrder.B@77468bd9 TAGB ---C //TAGB funA1: //TAGA funA1: