package com.bag;
class Super {
int i = 10; //1.3
Super() { //1.2
print(); //1.4 这个地方调用子类的print,由于此时子类的J还没有显示初始化,所有输出0
i = 20; // 1.5
}
void print() {
System.out.println(i);
}
}
public class Sub extends Super {
int j = 30; //1.6
Sub() { //1.1
print(); //1.7 这里j已显示初始化为30 所以输出30
j = 40; //1.8
}
void print() {
System.out.println(j);
}
public static void main(String[] args) {
System.out.println(new Sub().j); //1.0 //1.9这里主函数输出j为40
}
}
希望可以帮到你 |