Meaningless Drivel is fun!
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

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

Joined: Sep 28, 2004
Posts: 20531

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.


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
I agree. Here's the link:
subject: enum cannot be private or protected
It's not a secret anymore!