Monday, June 1, 2020

Java Modifier Keywords


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:
  1. Access control modifiers
  2. Non-access modifiers
MODIFIERDESCRIPTION
publicVisible to the world
privateVisible to the class
protectedVisible to the package and all subclasses
MODIFIERDESCRIPTION
staticUsed for creating class methods and variables
finalUsed for finalizing implementations of classes, variables, and methods
abstractUsed for creating abstract methods and classes
synchronizedUsed in threads and locks the method or variable so it can only be used by one thread at a time
volatileUsed in threads and keeps the variable in main memory rather than caching it locally in each thread

No comments:

Post a Comment