临近考试了,复习的时候遇到一个问题,程序是这样的:
public class Test
{
public static void main(String[] args)
{
boolean[][] x = new boolean[3][];
x[0] = new boolean[1];
x[1] = new boolean[2];
x[2] = new boolean[3];
System.out.println("x[2][2] is " + x[2][2]);
}
}
运行结果是:x[2][2] is false
可是,这里没有赋值,为什么会有运行结果呢?
------解决方案--------------------
boolean 是基本类型 默认值 是false
------解决方案--------------------
int 不赋值默认就是0,
boolean不赋值默认是false..
------解决方案--------------------
new boolean[3]
这样写会产生默认值的
------解决方案--------------------
------解决方案--------------------
默认值,基本类型都有默认值
boolean 默认 false
String 默认 null
int 默认 0
比如你创建一个 int数据 int[] intAry = new int[10];
System.out.println("intAry[8] is " + intAry[8]);
打印出来就是 0
------解决方案--------------------
boolean 是基本类型 默认值 是false
------解决方案--------------------
[Quote=引用:]
boolean 是基本类型 默认值 是false
同意
------解决方案--------------------
boolean 是基本类型 默认值 是false
正解!