Q 57. Given the following code
What code placed after the comment //Here will result in calling the getFields method resulting in the output of the
string "Agg"?
1) System.out.println(a.getFields());
2) System.out.println(a.name);
3) System.out.println((Base) a.getFields());
4) System.out.println( ((Agg) a).getFields());
Had there been a getFields() in class Base, I knew that the method would be invoked based on the object and not the reference type Base. I thought this was the rule which applied always to all instance,non-final methods, irrespective of whether they are overridden or not. the
method would be invoked based on the object . Going by this, I selected options 1 and 4, expecting this to give the same results whether I had a getFields() defined in class Base or not.
Well, I got it wrong

. Marcus explains that the correct answer is 4. The explanation -The Base type reference to the instance of the class Agg needs to be cast from Base to Agg to get access to its methods. The method invoked depends on the object itself, not on the declared type.
So, a.getField() invokes getField() in the Base class, which displays Base. But the call to ((Agg)a).getField() will invoke the getField() in the Agg class. You will be unlucky to get a question as complex as this on the exam.
I have compiled and verified that Marcus's answer is correct.
But I don't understand it. The object created is Agg, so why
does a.getFields invoke a.getField in the Base class ?
I have seen several answers in this forum where it is asserted that method invocation depends on the object, none of them seemed to mention that this is conditional(ie works only when overriding is in force).
Would really appreciate if someone could give an accurate explanation of how method invocation works with objects and references. I did look at the JLS but this particular section is not very clear to me.
thanks a ton!
cheers
Sajida