EMZETT.
Login

Access Modifiers

In short: Access modifiers determine from where classes, methods and attributes may be accessed.

In more detail: Java has four levels: public, protected, package-private (no keyword) and private.

In Depth

ModifierClassPackageSubclassEverywhere
publicyesyesyesyes
protectedyesyesyesno
(none)yesyesnono
privateyesnonono

Why?

They ensure encapsulation: data should only be changed through controlled methods (getters and setters).

See getter, setter, abstraction.

See also: public, private, protected, Getter