--Originally published at diegotc2016
Public
Public: it is visible to the world. A class, method, constructor, interface etc declared public can be accessed from any other class.
Private
Private: it is visible to the class only. Methods, Variables and Constructors that are declared private can only be accessed within the declared class itself.
No Modifier
No Modifier: it is the default and it is visible to the package. A variable or method declared without any access control modifier is available to any other class in the same package.
Protected
Protected: visible to the package and all the subclases. Variables, methods and constructors which are declared protected in a superclass can be accessed only by the subclasses in other package or any class within the package of the protected members’ class
I got this out of:
https://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html