爲什麼super
對i
字段C
沒有影響? 輸出爲012
,但爲什麼不是321
,因爲B
類擴展了C
類?java super for字段
public class C {
protected int i;
public C(int i){
this(i,i);
System.out.print(this.i);
this.i=i;
}
public C(int i, int j) {
System.out.print(this.i);
this.i=i+j;
}
public C(){
this(1);
System.out.print(i);
}
public static void main(String[] args) {
C c=new C();
}
}
public class B extends C{
public B(){
super.i=3;
}
public static void main(String[] args){
C c=new B();
}
}
難道真的nesseccary做
super.testMethod()
調用的方法testMethod
只是用不同的標題發表您的問題幾次? –今天同樣的問題 –
@Andreas:恩,這不是同一個問題,而是後續問題。 – Thilo