class A { public int a = 1; public int getA() { return a; } } class B extends A { public int a = 2; //public int getA() { return a + super.getA(); } //public int getA() { return a + super.a; } } public class FieldOverridingTest { public static void main(String[] args) { A instanceA = new A(); System.out.println("(A) instanceA.getA() = " + instanceA.getA()); instanceA = new B(); System.out.println("(B) instanceA.getA() = " + instanceA.getA()); B instanceB = new B(); System.out.println("(B) instanceB.getA() = " + instanceB.getA()); } } /* explanation: data fields can be overridden, i.e. subclass may have a field with the same name BUT behavior is different from methods: compile-time (variable) type determines which field is accessed RATIONALE: more efficient code possible, field overriding is rare, should possibly be avoided anyway only effects "public" and "protected" fields anyway, if we stick to "private" data fields + public accessor methods, there will be no problem */