File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes enums and protected modifier Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "enums and protected modifier" Watch "enums and protected modifier" New topic

enums and protected modifier

Sasha Ruehmkorf
Ranch Hand

Joined: Mar 29, 2007
Posts: 115
I just tried to declare a member of an enum protected and it worked. Protected-access would be exactly the same as the default-access as there will never be a subclass from an enum, is this right?
Ilja Preuss

Joined: Jul 11, 2001
Posts: 14112
Sounds right to me.

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Trond Valen

Joined: Aug 31, 2007
Posts: 1
I partly agree, it is the same as default access, but why is the protected modifier allowed for enum variables when enums can't be "subclassed"? I thought the main principle was that modifiers that make no sense or introduce redundancy are not allowed, just like classes can't be protected or private. In this case, protected is redundant, because it's the same as having no modifiers (default access).

But then again, protected variables are allowed in final classes, and enums can be seen as a special kind of final classes. This brings me to another question: can you always choose access modifiers for class and instance variables regardless of which modifiers the class has?
[ August 31, 2007: Message edited by: Trond Valen ]
I agree. Here's the link:
subject: enums and protected modifier
jQuery in Action, 3rd edition