+ -
当前位置:首页 → 问答吧 → 关于数组的一个问题~~

关于数组的一个问题~~

时间:2011-12-21

来源:互联网

临近考试了,复习的时候遇到一个问题,程序是这样的:
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

可是,这里没有赋值,为什么会有运行结果呢?

作者: Renita   发布时间: 2011-12-21

boolean 是基本类型 默认值 是false

作者: babyboy9685   发布时间: 2011-12-21

int 不赋值默认就是0,
boolean不赋值默认是false..

作者: bill0605030109   发布时间: 2011-12-21

new boolean[3]
这样写会产生默认值的

作者: funfenffun   发布时间: 2011-12-21