Boolean的默认值
boolean数据类型 boolean变量存储为8位(1字节) 的数值形式,但只能是false或true 且默认值为false.
当作为 构造函数 (带有 new ) 调用时, boolean() 将把它的参数转换为一个布尔值,并且 返回一个包含该值的boolean对象.
当作为一个 函数 (不带有 new ) 调用时, boolean() 将把它的参数转换成一个原始的布尔值,并且最终返回这个值.
public class Test {
static Boolean a;
static boolean b;
public static void main(String[] args) {
int x = 0;
int y =0;
if(a){
x++;
System.out.println("x="x);
}else {
y++;
System.out.println("y="y);
}
}
}
基本类型boolean默认值为false
而包装类Boolean默认值为null