I am learning Java recently, and I came across the notion of package-private
classes, which is the default if we don't specify anything. But then I realized:
I seldom see the use of package-private class. Is there a reason for this, e.g., it has serious drawbacks, it is redundant, or simply I am not reading enough? Are there strong arguments for/against its usage?
If it is really not useful in most cases, why would it be the default?
In what situation should we use package-private in the real world? I.e., when would it become irreplaceable?
In other words, what are the major pros and cons of the default package-private modifier?
One nice thing about package-private is that you can use it to give access to methods you would otherwise consider private to unit test classes. The downside of course being that other classes in the package could call it when they really shouldn't.
"Package Private" its used when you have several packages, and it means, other classes in the same package can access that class or class member as "public", classes in other packages cannot access, its like "private like them."