File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "access control modifier for enum" Watch "access control modifier for enum" New topic
Author

access control modifier for enum

nana ichi
Greenhorn

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
Greenhorn

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