It mainly includes knowledge about static, local variables, and instance variables.
Public class demo {
Static string STR [] = new string [5];
Public static void main (string ARGs []) {
System. Out. println (STR [1]);
}
}
Running result: NULL
Explanation:Static string STR [] = new string [5]; indicates a static attribute of the class. It does not belong to an object, belongs to a class, and is also an array of instance variables, if no initial value is assigned to the instance variable, the system automatically assigns the initial value to the instance variable: the initial value of int type is 0, the initial value of boolean type is false, and the initial value of Class Object type is null.
Differences between instance variables and local variables:
1. location: local variables are defined in the method, and instance variables are defined outside the class.
2. scope of use: local variables can only be used in the method defined by them. You can call the variable name directly.
instance variables can be used within the class at least, objects must be called for use
3. local variables must be initialized before they are used, and instance variables do not need to be assigned an initial value. The system will give the default initial value.
4. local variables cannot be duplicated in the same method. Local variables and instance variables can be duplicated. the proximity principle is used in the method. The local variables prevail. You can use this. instance variables call instance variables.