If you are maintaining or modifying production code -or- developing an API that you intend to export for other programmers to use, then the best answer is “you should never make classes public unless your clear intent is that your clients should be able to access your class and use it in their own client code .
Read moreWhat does it mean when a class is public?
public is a Java keyword which declares a member’s access as public. Public members are visible to all other classes . This means that any other class can access a public field or method. Further, other classes can modify public fields unless the field is declared as final .
Read moreCan a class be public?
Public means that the subject may be accessed by any class, protected by subclass , private by the class itself, no modifier means “package protected”, so the subject may be accessed by classes from the same package.
Read moreIs a class always public in Java?
In Java, a top-level class is either public or non-public . There is no “private”. You can only use the public keyword or leave it off. If you leave it off it is non-public, i.e., visible only to other classes in the same package.
Read moreCan a Java class be public or private?
No, we cannot declare a top-level class as private or protected. It can be either public or default (no modifier).
Read moreHow do you public a class in Java?
Java Classes and Objects
Read more