The access modifiers modify the default code element visibility, accessibility and forced memory allocation.
They are used as optional first keywords in class, interface, field and method declarations.
Usage: [public|protected|[default]|private] [static] [final] class/interface/field/method declaration
In case no modifier is defined, will mean default.
The static keyword defines that a field or method in a class will allocate memory to its contained data. These can be accessible without creating an instance from their class first.
A static code will allocate memory without using them, actually.
It is still possible to create an instance of such class.
In case the class which elements would be statically accessed is in a separated file, must be imported first in solo or with package.
Normal objects are allocated dynamically (run-time) while static contents statically (compile-time). Therefore, cross-referencing between non-static and static contents is not allowed.
The contents of the root class must be static.
EXAMPLE FOR ACCESSIBILITY WITHOUT STATIC KEYWORD:
EXAMPLE FOR ACCESSIBILITY WITH STATIC KEYWORD:
The final keyword defines that a variable (value) is immutable (unchangeable) or not.
For primitive type variables: the value is unchangeable.
For class (wrapper) type variables: the variable can not receive new instance.
In final cases the variable names should be written with upcase letters.
It is possible to allocate memory (render an instance) to a final variable later in the code but can be done only once.
For interfaces, all fields are final as default.
EXAMPLE FOR FINAL VARIABLES:
These methods can not be overridden in child classes.
EXAMPLE FOR FINAL METHOD:
Final classes can not be inherited.
EXAMPLE FOR FINAL CLASS: