There is a Class with inner classes. I expected that the output would be 6 9
but suddenly it gave me 0 9
. I wonder why I got such unexpected results?
It seems like in A
class the f1
variable somehow becomes zero.
Why does this happen?
public static void main(String[] args) {
new B(6);
}
public static class A {
private int f1 = 7;
public A(int f2) {
this.f1 = f2;
initialize();
}
protected void initialize() {
System.out.println(f1);
}
}
public static class B extends A {
protected int f1 = 3;
public B(int f1) {
super(f1);
this.f1 += f1;
initialize();
}
protected void initialize() {
System.out.println(f1);
}
}