Java Modifiers

What is this?

The following table shows which of the ten modifiers listed in the left column can be applied to each of the items in the other columns. For example, it shows that you cannot have private classes or static local variables. What it does not show is that public, private, and protected are mutually exclusive, and that final and volatile are also mutually exclusive.

The modifiers are keywords in the language that appear in the declaration of a class, method, or field:

An instance field is a variable that is declared outside of any method. A local field is a variable that is declared inside a method, possibly inside a local block inside a method.

The Table

Modifier Class Method Instance Field Local Field
public ok ok ok --
private -- ok ok --
protected ok ok ok --
static ok
(Inner classes only)
ok -- --
final ok ok ok ok
abstract ok ok -- --
synchronized -- ok -- --
transient -- -- ok --
volatile -- -- ok --
native -- ok -- --