The public keyword is a modifier that can be used in the declaration of classes and interfaces. (Note that the public keyword cannot be used in the declaration of local variables.) The public keyword can also be used as a modifier in the declaration of methods and variables. Classes or interfaces declared as public are visible everywhere. Methods and variables declared as public are visible everywhere their corresponding classes are visible.
Note that public classes must have a class name that exactly matches the name of the .java file in which they appear.