Member variables and local variables, member variables local variables
In java, variables can be divided into two categories based on their locations: member variables and local variables.
Member variables are defined in the class, including:
1. Class variable: modified in static mode. Scope: It exists from the preparation stage of the class until the system completely destroys the class. Same as the survival scope of the class
2. instance variable: not modified in static mode. Scope: The instance variable of the class starts to exist when it is created until the system completely destroys the instance. Same as the survival range of the corresponding instance
Class Test {
// Define instance variables
Public String name;
// Defines a class variable public static int price ;}
Local variables refer to the variables defined in the method, including:
1. form parameter: The variable defined in the method signature. Scope: valid throughout the method.
2. Local variables of the method: the local variables defined in the method body. Scope: The local variables take effect from the place where the variable is defined and expire at the end of the method.
3. code block local variable: The local variable defined in the Code block. Scope: takes effect from the place where the variable is defined until the code block ends.