今天一个好同学问我个问题,Boolean与boolean的默认值是多少?我就实践了下,希望对大家有帮助。
package com;
public class Test {
public Boolean bl;
public boolean b;
public static void main(String[] args){
Test test=new Test();
System.out.println("Boolean的默认值:"+test.getBl());
System.out.println("boolean的默认值:"+test.isB());
}
public Boolean getBl() {
return bl;
}
public void setBl(Boolean bl) {
this.bl = bl;
}
public boolean isB() {
return b;
}
public void setB(boolean b) {
this.b = b;
}
}
运行结果如下:
Boolean的默认值:null
boolean的默认值:false
package com;
public class Test {
public Boolean bl;
public boolean b;
public static void main(String[] args){
Test test=new Test();
System.out.println("Boolean的默认值:"+test.getBl());
System.out.println("boolean的默认值:"+test.isB());
}
public Boolean getBl() {
return bl;
}
public void setBl(Boolean bl) {
this.bl = bl;
}
public boolean isB() {
return b;
}
public void setB(boolean b) {
this.b = b;
}
}
运行结果如下:
Boolean的默认值:null
boolean的默认值:false