Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

enum cannot be private or protected

 
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
Marshal
Pie
Posts: 20999
76
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic