Access Modifiers in Java: Private
Access Modifiers in Java: Private
Access modifiers are used to specify the accessibility or access levels of a type (class,
interface) and its members (methods, variables and even constructors). There are three
access modifiers and four access levels in Java. The three access modifiers are are private,
protected and public. Four access levels (from most restricted to least restricted) are private,
default (no modifier), protected and public. If no access modifier is specified, it is called a
default access level.
The top level classes (classes not within another class) have only public and default access;
but for inner classes (classes within classes) have all four access levels.
Private
Private members are accessible only within the same class and also are not inherited.
Default
Default (no modifier) members can be accessed by members of the same class and
members of any class in the same package.
Default members are inherited by another class only if both parent and child are in same
package.
Protected
Protected members can be accessed by
subclasses (any level of subclass hierarchy) in other packages (only through inheritance).
Inherited protected members in the child class cannot be accessed using a parent reference
variable (irrespective of the object it point to at runtime).
class name
Public
Public members can be accessed from everywhere within your application either through
inheritance or through object reference.
Note that the class or packages should also be accessible to access its members. You will
not be able to access a public member from a default class from another package.
Source : http://javajee.com/access-modifiers-in-java