- Static modifiers (member variables, constants, and member methods decorated with the static modifier become static variables, constants, and methods, they are collectively called static members, are owned by the entire class, are not dependent on a particular instance of the class, are shared by all instances of the class, and, as long as the class is loaded, The JVM can find them in the method area of the run-time data area based on the class name)
- static variables
For static variables, at run time, the JVM allocates only one memory for static variables at a time, and completes the memory allocation of static variables during class loading. Inside a class, static variables can be accessed directly within any method, and in other classes, static variables in the class can be accessed through the class name.
Static variables can be shared by all instances of a class, so static variables can be used as shared data between instances, increasing the interactivity between instances.
If all instances in a class have an identical constant property, you can define this property as a static variable. For example:
Static Double pi=3.1415;
2. Static methods
A static method does not need to be called by any instance of the class it belongs to, so the This keyword cannot be used in a static method, nor can it directly access the instance variables and instance methods of the owning class, but the static and static methods of the owning class are directly accessible, and, as with this, Super is also related to a particular instance of a class, so it cannot be used in static methods.
Java final. Static modifier