2

Recently I'm quite oftenly using Enumerations. So I wonder...

Is there any difference between a private Enum constructor and a enum constructor withour any visibility modifier (package-private)?

MinecraftShamrock
  • 3,504
  • 2
  • 25
  • 44

2 Answers2

4

The constructor for enums is implicitly private, just like methods for interfaces and annotations are implicitly public abstract. The default is package local for class members.

BTW enum classes are implicitly final and nested enum classes are implicitly static.

Older constructs tend to allow you to add implicit modifiers, but newer constructs don't allow you to say. e.g. enums are final but you can't add final to an enum.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
  • I thought the default was package local, but once you start list all the combinations, you find it is more the exception than the rule. A bit like "i-before-e-except-after-c" which has some many exceptions. The rule holds for common words/cases. – Peter Lawrey Sep 09 '13 at 18:59
2

According to java docs

The constructor for an enum type must be package-private or private access.

but Accroding to the JLS

If no access modifier is specified for the constructor of an enum type, the constructor is private.

So there no difference between the package-private and private .

Prabhaker A
  • 8,317
  • 1
  • 18
  • 24