wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes access control modifier for 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 "access control modifier for enum" Watch "access control modifier for enum" New topic

access control modifier for enum

nana ichi

Joined: Apr 27, 2006
Posts: 7
Why can't enum be private or protected?
Leonardo Luiz
Ranch Hand

Joined: Mar 24, 2006
Posts: 51
I think is because an enum make sense only if it is accessible. Besides that an enum can't be extended.
Edisandro Bessa
Ranch Hand

Joined: Jan 19, 2006
Posts: 584
Hi Nana,

First of all, welcome to JavaRanch !

Enum is basically like any other class with some peculiarities. So the access modifiers rules for enums are the same as those used for a standard classes.

For the exam, keep in mind that you CAN define a enum as protected, private or even static only if such enum is a member of another class, otherwise, the only modifiers allowed are public or none (which behaves as default).

Here's an Example :

In summary, when you declare an enum as a member of any other class, you can use any modifier other than transient and volatile. In fact, an enum declared within a class behaves as it was a member of that class.
[ April 27, 2006: Message edited by: Edisandro Bessa ]

"If someone asks you to do something you don't know how to, don't tell I don't know, tell I can learn instead." - Myself
nana ichi

Joined: Apr 27, 2006
Posts: 7
Thank you for your explanation.
I agree. Here's the link: http://aspose.com/file-tools
subject: access control modifier for enum
Similar Threads
retrieve enumeration datatype into jsp
How to define constants for several classes?
Creating SingleTON without static variables
what results byte code in java
Enum Problem