First, we need to know the syntax for defining variables: Data type variable name = value;
Classabcstringinfo=null;voiddowork (Stringname) System.out.println (x); intage;
Variables are divided into two main categories, depending on where they are defined in the class:
Member variables: Global Variables/Fields (field), not called attributes, are defined directly in the class, outside of the method.
Class member variable: A field that is decorated with static, and an instance member variable: A field that does not use the static modifier.
Local variables: Variables except member variables, others are local variables.
A variable inside a method, a parameter of a method, a variable in a code block, or a variable in a pair of {}.
Initial value of the variable: the initialization of the variable will only open up space in memory.
Member variables: default is the initial value, see;
Local variable: There is no initial value, so it must be initialized before it can be used.
Open Baidu app to see more beautiful pictures
The initial value of the variable
Variable scope: Variables are defined differently depending on the location, and the respective scopes are different, mainly the pair {} where the variables are located.
Member variables: Valid throughout the class, local variables: start at the beginning of the defined position, and close to the end of the common parenthesis.
Member variables can be defined first, and local variables must be defined before they are used.
Rules for variable usage in Java