Dynamic binding works for methods. Why not for other members [variables]? [duplicate]
问题 This question already has answers here : Java Inheritance - instance variables overriding (3 answers) Closed 6 years ago . In the following program. methods are called as per type dynamically. But how about calling variables dynamically. why can't it do so? class Super { public int field = 0; public int getField() { return field; } } class Sub extends Super { public int field = 1; public int getField() { return field; } public int getSuperField() { return super.field; } } public class