java static

java static


1.static variables and methods can be inherited
2.static variables and methods belong to classes, which do not belong to that instance
3.static variables will have thread safety problems
4. can not put any method in the body The variable is declared as static (declaring a static variable in the method body will report an error)
5. To access static constants, if the compiler can calculate the value of the constant, the class will not be loaded. That is, if the static constant value of class A is assigned by the static constant of class B, it will not be loaded, otherwise class A needs to be loaded.
6. To access static constants, if the compiler can calculate the value of the constant (that is, the value will not change), the class will not be loaded, otherwise the class will be loaded
7. Static methods and static name blocks cannot call non-static variables and non-static variables. Static methods
8. This and super cannot be used in static methods. When


the
subclass calls the static method of the superclass (1) when the subclass does not override the static method of the superclass, only the superclass is loaded, and the subclass is not loaded
(2) When When a subclass has a static method that overrides the parent class, it loads both the parent class and


the execution order of the subclass static{} statement block
(1) When there are multiple static{} in a class, according to the definition of static{} Sequence, executed from front to back; (writing sequence execution)
(2) The content of the static{} statement block will be executed first, and then the main call statement will be executed;

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326983532&siteId=291194637