面试题错题集03(数组)

10、以下代码的执行结果是? D  

public class Example {

 public static void main(String[] args) {

  Element[] a1 = new Element[1];

  Element[][] a2 = new Element[2][1];

  Element[][][] a3 = new Element[3][3][3];

  System.out.print(a3[2][2][2]);

  a1[0] = new Element();

  a2[0] = a2[1] = a1;

  a3[0] = a3[1] = a3[2] = a2;

  System.out.print(a3[2][2][2]);

 }

}

 

class Element {

}

A、输出0

B、输出null

C、编译不能通过

D、运行时输出异常

// 数组越界异常 因为此时a3[0]: a2[0][0] a2[1][0]

原文地址:https://www.cnblogs.com/heureuxl/p/13444160.html