创建对象时,该对象的成员变量如果不赋值的情况下,默认值是
基本类型的初始值 基本类型 默认值
boolean false
char u0000(null)
byte (byte)0
short (short)0
int 0
long 0L
float 0.0f
double 0.0d
代码如下:
public class BaseType {
private byte aByte;
private short aShort;
private int anInt;
private long aLong;
private double aDouble;
private float aFloat;
private char aChar;
private boolean aBoolean;
@Override
public String toString() {
return "BaseType { " +
"aByte=" + aByte +
", aShort=" + aShort +
", anInt=" + anInt +
", aLong=" + aLong +
", aDouble=" + aDouble +
", aFloat=" + aFloat +
", aChar=" + aChar +
", aBoolean=" + aBoolean +
'}';
}
}
测试类
public class Test {
public static void main(String[] args) {
BaseType baseType = new BaseType();
System.out.println(baseType);
System.out.println("u0020");
}
}
扩展: char 打印出来的,不是null、也不是空格,是一个空
空用unicode编码标识是:u0000
空格unicode编码标识是:u0020