Hello Thomas,
The code posted by Jordi will not compile as the there is no method named getFields() defined in the class Base.It will compile if we cast the reference variable a for the object of class Agg like ((Agg) a).getFields().
It will make you understand dynamic binding or
polymorphism much much better.
If you remove getFields() from Base class, you actually take getFields() out of the polymorphism between Base and Agg class. Compiler only know b is refer to a Base class, which does not have the method getFields(), compile time error!!!
Remember Agg ISA Base. Compiler does not care which child/grandchild/grandgrandchild down the hierarchy b is actually referring to, and which getFields() it should call. However, they all have an getFields() (polymorphism). It is a runtime decision. Dynamic Binding.
Dynamic binding, or binding at runtime only for those methods defined in Base class, either inherited or overrided by the subclass. The override can be already happened now or will happen in the future, the compiler does not care.
I hope it will help.
Gurpreet Sachdeva
Please visit for all type of info. about
SCJP (Including mock exams) at:
http://www.go4java.20m.com
Regards<BR>Gurpreet Sachdeva<P>For Mock Exams, FAQ, Exam tips and some useful information about Bitshift operator, inner classes, garbage collection,etc please visit: <A HREF="http://www.go4java.lookscool.com" TARGET=_blank rel="nofollow">http://www.go4java.lookscool.com</A>