public class Base {
private static boolean goo = true;
protected static boolean foo() {
goo = !goo;
return goo;
}
public String bar = "Base:" + foo();
public static void main(String[] args) {
Base base = new Sub();
System.out.println("Base:"+ base.foo());
}
}
public class Sub extends Base {
public String bar = "Sub:" + foo();
protected static boolean foo() {
return false;
}
}
Why the output is "Base: true"? foo() seems to be an overriding method so dynamic type is Sub, than why the return output isn't "false", and also the field of Base has a string, shouldn't there be its output?