This week's book giveaway is in the Big Data forum.
We're giving away four copies of Elasticsearch in Action and have Radu Gheorghe & Matthew Lee Hinman on-line!
See this thread for details.
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 Elasticsearch in Action this week in the Big Data forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Enum - Constant Specific Class Body" Watch "Enum - Constant Specific Class Body" New topic

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%
I agree. Here's the link:
subject: Enum - Constant Specific Class Body
Similar Threads