Tag: Member variable This uses part of this keyword storage space to improve
Static declares the member variables of the class and the characteristics of the method. The method declared by 1.1:static is a static method, and the member variable of the static declaration is a static member variable. For all objects of the class, static member variables and static have only one copy of storage space 1.2: You can use the static member variable and the static method, even if the object for that class is not created.
Static modified member variables and block blocks are created when the virtual machine loads the class, even if the class is not initialized and the object is not created, and the Java virtual machine can find them within the method of the run-time data area based on the class name. ( the Scarlet Letter section will be followed by a detailed article.) )
1.3: The This keyword cannot be used in static methods
This is also very well understood. When an object is created, the Java Virtual machine assigns it a pointer that refers to itself: this. This means that this is a reference to the current object . The Scarlet Letter section says that the object is a reference to the current object, and when the static method is executed it may not be initialized and the This keyword cannot be referenced in the static method. In the same way that it is not the This keyword, any non-static member variables cannot be accessed in the static method. Similarly, non-static member variables are created when the class is initialized
1.4: The main method as the entrance to the program is the static method
The main () method is defined as the static method of static, and the Java Virtual machine executes the main method as long as the class to which the main method belongs is loaded. Without first creating a real column of this class
Add: Whether it is a static method or a normal method, his bytecode is in the method area .
features of the 2:final keyword
2.1. Final modified member variables become constants that can never be changed, and constants must be displayed for initialization
2.2. Final modified methods cannot be overridden (that is, when a subclass inherits from a parent class, the final method of the parent class cannot be overridden
Summary: The final keyword is primarily system security. Modifying a member variable together with static, that is, statically constant, writes some static constants in the code, and can improve the readability of the program.
In-depth understanding of static keywords in Java