class Main {
public static void main(String[] args) {
new B();
}
public static class A {
String f1 = "300";
public A(){
init();
}
protected void init(){}
}
public static class B extends A {
private String f1 = "3";
public B(){
super();
init();
}
protected void init(){
System.out.println(f1);
}
}
}
Output:
null
3
Can anyone explain to me the first line of the output? If I delete the line String f1 = "300";
, it still has the same output also.
I have tried that if I declare some variables in B
and invoke it in init()
and all of it will be null
in the constructor of A
. In other words, my question is I want to know the reason for those variables being null
at that point.