What\'s the reason of making top-level class non-public in Java?
Let\'s say we have Foo.java
, there could be
class Foo {
}
Classes without a public
or protected
modifier are only visible inside the package they reside. If you think of components and interfaces there is a reason for leaving out the public
modifier. Let's say you have a public
class MyCompontent
that internally uses other classes, but does not want to publish those to the outside world (users of the component) it makes sense to leave out the visibility modifier.