The types of variables supported by the Java language are:
1, class variables: Variables independent of the method, modified with static
2, instance variable: A variable independent of the method, but without the static modifier
3, local variable: A variable in a method of a class.
Public class variable{ staticint allclicks=0; // class Variables String str= "Hello World"; // instance variable Public void method () { int i =0; // Local Variables }}
Second, Java Local variables
1, the local variable is declared in the method, the construction method or the statement block ;
2, local variables are created when the method, construction method, or statement block is executed, and when they are executed, the variables are destroyed;
3, the access modifier cannot be used for local variables.
4, a local variable is visible only in the method that declares it, in the construction method, or in the statement block.
5, local variables are allocated on the stack.
6, the local variable has no default value, so the local variable is declared and must be initialized before it can be used.
Three, instance variables
1, instance variables are declared in a class, but outside of methods, construction methods, and statement blocks;
2, when an object is instantiated, the value of each instance variable is then determined;
3, the instance variable is created when the object is created and destroyed when the object is destroyed;
4, the value of the instance variable should be referenced by at least one method, construct method or statement block, so that the external can obtain the instance variable information through these methods;
5, the instance variable can be declared before use or after use;
6, the access modifier can modify the instance variable;
7, instance variables are visible to methods, construction methods, or block statements in a class. In general, you should set the instance variable to private. By using the access modifier, the instance variable is visible to the child class;
8, the instance variable has a default value. The default value for a numeric variable is 0, the default value for a Boolean variable is false, and the default value for the reference type variable is null. The value of a variable can be specified at the time of declaration, or it can be specified in a constructor method;
9, the instance variable can be accessed directly from the variable name. However, in static methods and other classes, you should use the fully qualified name: Obejectreference.variablename.
Java Variable type