Access level modifiers determine whether other classes can use a particular field or invoke a particular method.
The following table shows the access to members permitted by each modifier.
Access Levels | ||||
Access Specifiers | Class | Within Package | Outside package + Subclass | World |
public | Y | Y | Y | Y |
protected | Y | Y | Y | N |
Package-private | Y | Y | N | N |
private | Y | N | N | N |
The first data column indicates whether the class itself has access to the member defined by the access level. As you can see, a class always has access to its own members. The second column indicates whether classes in the same package as the class (regardless of their parentage) have access to the member. The third column indicates whether subclasses of the class declared outside this package have access to the member. The fourth column indicates whether all classes have access to the member.