Java中
引用类型初始化后未赋值之前的值为null
基本数据类型
byte、short、int、long、boolean、char、float、double
这里要注意char类型初始化之后的默认值为空白(注意:不是空格)
import java.util.Arrays;
public class Test {
public static byte byte1;
public static short s;
public static int i;
public static long l;
public static char c;
public static boolean boolean1;
public static float f;
public static double d;
@org.junit.Test
public void test() throws Exception {
System.out.println("byte:" + byte1); //byte:0
System.out.println("short:" + s); //s:0
System.out.println("int:" + i); //i:0
System.out.println("long:" + l); //l:0
System.out.println("char:" + c); //char:
System.out.println("boolean:" + boolean1); //boolean:false
System.out.println("float:" + f); //l:0.0
System.out.println("double:" + d); //l:0.0
}
}
本文详细解析了Java中基本数据类型的默认值,包括byte、short、int、long、boolean、char、float和double,并通过代码示例展示了这些类型在未初始化时的默认状态。
3348

被折叠的 条评论
为什么被折叠?



