Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Enum - Constant Specific Class Body

 
Faber Siagian
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I expect the result : 800 100, because ICELANDIC has its own height.
But actually it is 800 13. Would someone explain this?
 
Santhosh Kumar
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Santhosh, great. Thanks.
 
Milan Sutaria
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nice Question & great Reply ... thanks
I thought of playing with it a bit


[ July 10, 2008: Message edited by: neo Tux ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Similar Threads