I put my question on comment section in the code. I have already passed the verification. But I still don't understand why it displays 0 in protected modifier.
public class Solution {
public static void main(String[] args) {
new B(6);
}
public static class A {
private int f1 = 7;
public A(int f1) {
this.f1 = f1;
initialize(); //The reason why it displays 0 rather than 6 is because this method calls B.initialize() rather than A.initialize(), right? But why?
} //Can any one suggest Codegym lessons that can explain why this is happening?
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);
}
}
}