I expect the result : 800 100, because ICELANDIC has its own height. But actually it is 800 13. Would someone explain this?
Sun Certified Programmer for the Java 2 Platform, Standard Edition 5.0 (88 %)
Joined: Nov 07, 2000
Variables cannot be overriden by the subclasses and are always referred through the type of the reference rather than the instance of the reference.
In your case, ICELANDIC is an instance of subclass of Horse and others are just instances of Horse. However you are referring to all the instances through Horse type reference so variables value would be from Horse type (not based on the actual instance type). Check out these simple classes, and you might get some idea.
The output is
[ July 09, 2008: Message edited by: Santhosh Kumar ]
Joined: Jul 08, 2008
Hi Santhosh, great. Thanks.
Joined: Jul 10, 2008
Nice Question & great Reply ... thanks I thought of playing with it a bit