Difference between a public and a non-public class.A class with access specifier ‘public’ can be accessed across the packages. A package is like a folder in GUI based operating systems. For example, the “public class String” class is a public class which can be accessed across the packages.
A non-public class is a class without public access specifier. A class without access specifier or with “protected” access specifier is called non-public classes.
If a class is specified protected access can be accessed in other packages but only by the subclasses. The class without access specifier can be accessed only within the package.