-
In the Java language we describe a class or a method, often using public , private,protected Three keywords, there is also the default access rights, that is, nothing to write.
First we introduce the Public keyword, from the literal point of view, publicly meant to be common, it can be seen that its access is very lenient, is everyone's public.
Public access is the most lax, it can be accessed within the same package, or it can be accessed within different packages, which means that the element immediately followed is available to anyone,
-   the
is then private, literally, it means private, and it can be seen that the access rights are more stringent.
It represents an element that cannot be accessed by anyone other than the type creator and the internal method of the type. It's like a wall, and when someone tries to access it, they get an error message at compile time.
-
Protected, which is literally protected, is equivalent to the private keyword, The difference is that the inherited class can access the protected member, but cannot access the private member.
-  
Finally, Java also has a default access permission that, when not used to any of the previously described access-specific permissions, will work, which is known as package access , because under this permission, a class can access members of other classes in the same package, but outside of the package, these members behave as if they were private.
Summary: Generally we use public to modify the tool class when it is defined, because it is obvious that the tool class is to be available to everyone, so it must be defined as public. And in other classes that you don't want others to be able to make new, We usually use private. A summary of the various visits is shown in the picture.
How to differentiate public,private,protected in Java