aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes enum cannot be private or protected 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 "enum cannot be private or protected" Watch "enum cannot be private or protected" New topic
Author

enum cannot be private or protected

Raja Narasimha
Ranch Hand

Joined: Nov 28, 2010
Posts: 33
Hi, Why enum cannot be private or protected ?
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18995
    
  40


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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
Don't get me started about those stupid light bulbs.
 
subject: enum cannot be private or protected