class Base {
private int base = 10; public Base() {
test(base);
System.out.println(base + "1");
} void test(int base) { ++this.base;
}
}class Child extends Base {
private int child = 20; public Child() {
test(child);
System.out.println(child + "2");
} void test(int child) { --this.child;
} public static void main(String[] args) {
new Child();
}
}为什么上面那段代码输出的结果是101
192
101是怎么输出的,不是很理解,有大神可以讲解一下吗?
楼主可以在test(int child)里加一句:
System.out.println("child now is "+this.child);
更利于理解初始化的过程。