This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes about enum Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "about enum" Watch "about enum" New topic
Author

about enum

vasu chowdary
Ranch Hand

Joined: Mar 15, 2008
Posts: 89
can an enum be extended?
Tarun Kumar
Greenhorn

Joined: Apr 30, 2008
Posts: 26
NO ENUM CAN NOT BE EXTENDED


Tarun Kumar
Laura Montes
Greenhorn

Joined: Aug 03, 2007
Posts: 9
Hi!

Well, it's clear for me that an ENUM cannot extend because I've tried and it doesn't compile but why not?

I found a tutorial in java.sun.com that says the following:

Note: All enums implicitly extend java.lang.Enum. Since Java does not support multiple inheritance, an enum cannot extend anything else.


I search this class in the API and I found that its signature.

public abstract class Enum<E extends Enum<E>>extends Object implements Comparable<E>, Serializable

Can anyone explain further, pls?
Am I right with what I found ?

Thanks & regards,
Lau
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Well, yes, what you found is true. An enum can't be made to extend some other class because it is already (implicitly) extending something.

But my impression is that the original question was whether something could extend an enum. (I could be wrong but that's what it looks like to me.) And that's the opposite question to the question you answered.
Laura Montes
Greenhorn

Joined: Aug 03, 2007
Posts: 9
Oh, I got it, they mean subclass an enum... well and Why not?. I don't see that the enum class is final.

Regards,
Lau
Dumitru Postoronca
Ranch Hand

Joined: May 06, 2008
Posts: 46

Line 1&2 compiles, line 3 does NOT (it says: x must be a class).
So, ENUMs ca[LIST]
  • implement interfaces
  • Dumitru Postoronca
    Ranch Hand

    Joined: May 06, 2008
    Posts: 46

    Line 1&2 compiles, line 3 does NOT (it says: x must be a class). Line 4 also does NOT compile (extends is not expected to be there).


    So,
  • ENUMs can implement interfaces
  • ENUMs can NOT extend anything (either class or another enum)
  • ENUMs can NOT be subclassed
  • Ben Souther
    Sheriff

    Joined: Dec 11, 2004
    Posts: 13410

    "vasu",
    Please check your private messages regarding an important administrative matter.
    -Ben


    Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: about enum
     
    Similar Threads
    Creating SingleTON without static variables
    Enum Problem
    retrieve enumeration datatype into jsp
    How to define constants for several classes?
    what results byte code in java