Default values of java static variables, member variables, and local variables

Default values ​​of java static variables, member variables, and local variables

Default values ​​of static variables and member variables

The default values ​​of static variables and member variables are the same

public class Variable{
    
    
	public static char a;
	public char b;
	…………
}

静态成员、成员变量char默认值: 
静态成员、成员变量int默认值:0
静态成员、成员变量long默认值:0
静态成员、成员变量float默认值:0.0
静态成员、成员变量double默认值:0.0
静态成员、成员变量boolean默认值:false
静态成员、成员变量string默认值:null
静态成员、成员变量char默认值为空

ps:The default value of the char type is not null, it is \u0000 (the default value of 0) The
char type cannot be judged by null, such as char c;

if(c==null)……

Illegal operation! ! !

Determine whether char is assigned

For example, for char c;
use \u0000 or 0 to judge

if(c=='\u0000')……
或者
if(c==0)……

Default value of local variable

Local variables are only declared without default values ​​and
must be assigned initial values

Of course, if new is the same as the default value

Guess you like

Origin blog.csdn.net/qq_36976201/article/details/112071413