class X {
int x1, x2, x3;
}
class Y extends X {
int y1;
Y() {
x1 = 1;
x2 = 2;
y1 = 10;
}
}
public class Test {
public static void main(String[] args) {
Y y = new Y();
System.out.println(y.x1 + "," + y.x2 + "," + y.x3 + "," + y.y1);
}
}
哪個構造函數初始化變量x3?哪個構造函數初始化變量x3?
- 默認類的構造函數
X
- 默認
Object
類
您怎麼看?爲什麼? – Pshemo
x3未實例化 –
@AlexandruSeverin字段總是被初始化,但並非總是與默認值不同。 – Pshemo