Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

enum cannot be private or protected  RSS feed

 
Raja Narasimha
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Why enum cannot be private or protected ?
 
Henry Wong
author
Sheriff
Posts: 22843
119
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Actually, enums can be private or protect. It is just that top level enums that can't be private or protected.

Enums are very similar to Classes, and top level classes are not allowed to be private or protected. As for why top level classes can't be private or protected, please search the forums as this question comes up often.

As a quick summary though, it is less like it is not allowed, and more like there is no definition (what the compiler should do). The JLS doesn't define what is a top level private or protected class, and the definition for inner and nested classes doesn't apply. So, no definition mean you can't compile code which means that you can't allow it.

Henry
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!