• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Query on enum

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello All,
Please look into the following code:



This particular code compiles and even runs perfectly . The output is 0. But my question is what is method ordinal() here. We haven't defined this method in our enum. Is this something defined in java.lang.Enum?

2) Can an enum implement an interface. If so can any one post me a sample code snippet?

3) Can an enum be extended. If so, should that be an enum only or can it be a class?

Please clarify me on this.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
An enum in Java is like a special kind of class. The superclass for an enum type is java.lang.Enum. The ordinal() method is defined in that class - you can look it up in the API documentation.

Besides the methods in java.lang.Enum, an enum also has two implicitly declared static methods: public static E[] values(); and public static E valueOf(String name);

For all the details, see The Java Language Specification, section 8.9.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the information Jasper.
 
I think she's lovely. It's this tiny ad that called her crazy:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic