I know, there is an implicit super() statement in the constructor of the subordinate class, but how do the class fields, instance fields, and constant fields are initiated and their order in super class and subordinate class, also where are the method information stored?
As demonstrated below, the output of the program is "null
", but it will be "child
" if I add the static modifier before s in the child class. I suppose that to explain such result, the answer to the questions above is essential.
public class Parent {
private String s = "parent";
public Parent() {
call();
}
public void call() {
System.out.println(s);
}
public static class Child extends Parent {
private /*static*/ String s = "child";
public Child() {
}
public void call() {
System.out.println(s);
}
}
public static void main(String[] args) {
Child child = new Child();
}
}