Modifiers in Java are keywords that you add to variables, classes, and methods in order to change their meaning.
FINAL:
- if a class is declared as final, it can not be inherited (or extended)
- if a method is declared as final, it is not possible to override that method in the child class
- if a variable is declared , reassignment is not possible
- instance methods are bond with objects, and static methods are bond with class
- class containing main method is executed by JVM
- final class variables are not a final but final class methods are final by default ( because extension is not possible)
They can be broken into two groups:
- Access control modifiers
- Non-access modifiers
MODIFIER | DESCRIPTION |
---|---|
public | Visible to the world |
private | Visible to the class |
protected | Visible to the package and all subclasses |
MODIFIER | DESCRIPTION |
---|---|
static | Used for creating class methods and variables |
final | Used for finalizing implementations of classes, variables, and methods |
abstract | Used for creating abstract methods and classes |
synchronized | Used in threads and locks the method or variable so it can only be used by one thread at a time |
volatile | Used in threads and keeps the variable in main memory rather than caching it locally in each thread |
No comments:
Post a Comment