临近考试了,复习的时候遇到一个问题,程序是这样的:
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可是,这里没有赋值,为什么会有运行结果呢?
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..
这样写会产生默认值的
boolean 默认 false
String 默认 null
int 默认 0比如你创建一个 int数据 int[] intAry = new int[10];
System.out.println("intAry[8] is " + intAry[8]);打印出来就是 0
boolean 是基本类型 默认值 是false
同意
正解!