According to the following quote, I expect to see overriden nullstackoverflow
instead of overriden nullnull
. What point did I miss?
Within a class, a field that has the same name as a field in the superclass hides the superclass's field, even if their types are different.
class A {
public static void main(String[] args) {
new B("message is here");
}
protected int i = 13;
public void print() { System.out.println("Hello"); }
public A() { i = 13; print(); }
}
class B extends A {
private String i = "stackoverflow";
private String msg;
public void print() { System.out.println("overriden " + msg + i); }
public B(String msg) { super(); this.msg = msg; }
}