This week's giveaway is in the Spring forum.
We're giving away four copies of Learn Spring Security (video course) and have Eugen Paraschiv on-line!
See this thread for details.
Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

access control modifier for enum

 
nana ichi
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why can't enum be private or protected?
 
Leonardo Luiz
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 584
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
nana ichi
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your explanation.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic