Hello all. I've gone through K&B completely, and I'm finally back for my first query
.
In Chapter-2, it has been mentioned in an ExamWatch box that
if a method is overriden but we use a supertype reference to refer to the subtype object with the overriding method, the compiler assumes that we're calling the supertype version of the method. Aight. This has me a bit confused, and I want to know whether I've interpreted it right. We have a Horse and Animal example given as follows (pardon the C++ style indentation, I can never let go of that...lol) -:
As per the bold text, the compiler assumes that we're calling the supertype version of the eat() method. Yet, the output is -:
Generic
Omnomnom
This seems to contradict what's given in the box.
If I've interpreted this correctly, does this mean that at runtime, the compiler's understanding is overruled and b is actually pointing to a Horse object is found out?