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