| Author |
Enum - Constant Specific Class Body
|
Faber Siagian
Ranch Hand
Joined: Jul 08, 2008
Posts: 52
|
|
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 %)
|
 |
Santhosh Kumar
Ranch Hand
Joined: Nov 07, 2000
Posts: 242
|
|
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 ]
|
 |
Faber Siagian
Ranch Hand
Joined: Jul 08, 2008
Posts: 52
|
|
|
Hi Santhosh, great. Thanks.
|
 |
Milan Sutaria
Ranch Hand
Joined: Jul 10, 2008
Posts: 118
|
|
Nice Question & great Reply ... thanks I thought of playing with it a bit [ July 10, 2008: Message edited by: neo Tux ]
|
SCJP 6 83%
Working on SCWCD/OCPJWCD
|
 |
 |
|
|
subject: Enum - Constant Specific Class Body
|
|
|