https://www.cnblogs.com/shanqiang1/p/10759279.html
//父类
class Foo {
int i = 1; //-----------(1)
Foo() {
System.out.println(i); //-----------(3)
int x = getValue();
System.out.println(x); //-----------(5)
}
{
i = 2; //-----------(2)
}
protected int getValue() {
return i;
}
}
//子类
class Bar extends Foo {
int j = 1; //-----------(6)
Bar() {
j = 2; //-----------(8)
}
{
j = 3; //-----------(7)
}
@Override
protected int getValue() {
return j; //-----------(4)
}
}
public class TestCls {
public static void main(String[] args){
Bar bar = new Bar();
System.out.println(bar.getValue());
}
}
/* Output:
2
0
2
*/