It allows the programmer to control the visibility of class members. When a class member is preceeded by public, then that member may be accessed by code outside the class in which it is declared.
The private access specifier is just the opposite of public.It prevents a member from being used by code defined outside of its class.
Variables and methods declared protected are accessible from the classes defined in the same package and also from subclasses which are defined in other packages.
we do not explicitly declare an access modifier for a class, field, method, etc.A variable or method declared without any access control modifier is available to any other class in the same package. The fields in an interface are implicitly public static final and the methods in an interface are by default public.