wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Enum - Constant Specific Class Body Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Enum - Constant Specific Class Body" Watch "Enum - Constant Specific Class Body" New topic
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: 122
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
 
jQuery in Action, 2nd edition
 
subject: Enum - Constant Specific Class Body
 
Similar Threads