d.i是父类的,子类继承了它,当执行子类的构造,自动调用父类的无参构造,i的值变成了2,然后执行子类自己的构造,将i的值变成了5,所以输出的是5.
class Super {
int i = 0;
public Super(String a) {
System.out.println("A");
i = 1;
}
public Super() {
System.out.println("B");
i += 2;
}
}
class Other_Demo extends Super {
public Other_Demo(String a) {
// super();
System.out.println("C");
i = 5;//这个i是从父类继承的
}
}
class Test {
public static void main(String[] args) {
int i = 4;
Super d = new Other_Demo("A");
//
System.out.println(d.i);
}
} |