Java static keyword
The static keyword is used to
- create variables that will exist independently of any instances created for the class. Only one copy of the static variable exists regardless of the number of instances of the class. Static variables are also known as class variables. Local variables cannot be declared static.
- create methods that will exist independently of any instances created for the class. Static methods do not use any instance variables of any object of the class they are defined in. Static methods take all the data from parameters and compute something from those parameters, with no reference to variables. Class variables and methods can be accessed using the class name followed by a dot and the name of the variable or method.
- create block that can be used to initialize static variables or execute static methods once when classloader loads the class.
Published on 22-Apr-2018 23:29:53