Modifiers in Java
Modifiers Matrix
This table (matrix) shows which modifier to which element can be applied.
See a matrix of the Protection Modifiers in Java - how they set the visibility and the access rights.
| element | Data field | Method | Constructor | Class | Interface | ||
|---|---|---|---|---|---|---|---|
| modifier | top level (outer) |
nested (inner) |
top level (outer) |
nested (inner) |
|||
| abstract | no | yes | no | yes | yes | yes | yes |
| final | yes | yes | no | yes | yes | no | no |
| native | no | yes | no | no | no | no | no |
| private | yes | yes | yes | no | yes | no | yes |
| protected | yes | yes | yes | no | yes | no | yes |
| public | yes | yes | yes | yes | yes | yes | yes |
| static | yes | yes | no | no | yes | no | yes |
| synchronized | no | yes | no | no | no | no | no |
| transient | yes | no | no | no | no | no | no |
| volatile | yes | no | no | no | no | no | no |
| strictfp | no | yes | no | yes | yes | yes | yes |
Rules
- a method declaration can contain only one of the access modifiers public, protected and private
- classes cannot be declared abstract and final simultaneously
- abstract methods cannot be declared private, static, final, native, strictfp or synchronized
- methods cannot be declared native and strictfp simultaneously
- abstract and native
methods have no body
abstract void method();native void method();
- a class that contains abstract method(s) must be declared abstract
- final fields cannot be volatile