Why can a enum have a package-private constructor?

The constructor actually isn’t package-private… it’s implicitly private the way interface methods are implicitly public even if you don’t add the keyword. The relevant section of the JLS (ยง8.8.3) states: If no access modifier is specified for the constructor of a normal class, the constructor has default access. If no access modifier is specified for … Read more

Pros and cons of package private classes in Java?

The short answer is – it’s a slightly wider form of private. I’ll assume that you’re familiar with the distinction between public and private, and why it’s generally good practice to make methods and variables private if they’re going to be used solely internally to the class in question. Well, as an extension to that … Read more