1、布尔型(boolean)变量默认值为false,byte、short、int、long为0,字符型为’\u0000’(空字符),浮点型(float double)为0.0,引用类型(String)为null。
package cn.nxl2018;
public class Test {
private boolean bool;
private byte bt;
private short st;
private char ch;
private int i;
private long l;
private float f;
private double d;
private String str;
public static void main(String[] args){
int j;
Test test=new Test();
System.out.println(test.bool);
System.out.println(test.bt);
System.out.println(test.st);
System.out.println(test.ch);
System.out.println(test.i);
System.out.println(test.l);
System.out.println(test.f);
System.out.println(test.d);
System.out.println(test.str);
}
}
2、注意:未初始化的局部变量是不可以使用的,在这里可以认为是因为局部变量没有默认值,所以不可以直接使用。空字符(‘\u0000’)什么也不输出,不要认为输出是空格。
关联博客(博客园):http://www.cnblogs.com/qikeyishu/p/8996259.html