There are four usage scenarios in the Java language: member variables, member methods, code blocks, and inner classes
(1) static member variable
In Java, you can achieve the effect of global variables by statin keyword modifiers. Static modified variables are classes that are allocated memory space the first time a class is passed through the class loader to the JVM.
(2) static Member method
The static modified method belongs to a class method and can be called without creating an object. Keywords such as this and super cannot be used in the static method and cannot be called a non-static method, only static member variables and static methods of the owning class can be accessed.
(3) Static code block
The JVM executes a static block of code when it loads the class, which is often used to initialize the statically variable, and the static code executes and executes only once when the class is loaded.
(4) Static inner class
The static inner class can be instantiated without relying on an external class instance object, while an inner class needs to be instantiated after an external class instantiation.
Static inner classes cannot access ordinary variables of external classes, only static member variables and static methods of external classes.
The role of the static keyword in Java