Variables in Java---class variables (static variables), final variables, member variables, local variables
A ① class variable (also called a static variable) is a variable that is independent of the method in a class, and static modifiers are loaded with the load of the class .
② final variable : decorated with the final keyword and cannot be modified. Used with static to represent constants.
③ member Variable (also called "Instance variable", "Domain"): is also a variable independent of the method in the class, but there is no static adornment. It can be initialized without initialization , and if the reference type is initialized to null by default, the base type, such as int, is initialized to 0 by default.
④ local variable is a variable in a method of a class. Must be instantiated, otherwise different by compiling. Local variables are allocated in the stack , the volume is large, the life cycle is short, if the virtual machine to each local variable is initialized, is a very large cost, but the variable is not initialized to the default value is not safe to use. Due to the two aspects of speed and security, the solution is to not initialize the virtual machine, but it is required that the writer must assign a value to the variable before using it.
1 public class variable{ 2 static int allclicks=0; // class variable 3 String str= "Hello World"; // instance variable 4 public void method () { 5 int i = 0; // local variable 6 } 7 }
Essays in ⑨java Variables---class variables (static variables), final variables, member variables, local variables