Array.

  We have to keep in mind that,the 'new' keyword create an array at the runtime rather that at the compile time,that is,at the compile time,jvm just check the syntax.

 1 /*
 2 Array demonstration.
 3 Note that, the 'new' keyword does not create an array of 'a' until the runtime,that is,at the compile time,the jvm just check the syntax.
 4 */
 5 import kju.print.Print;
 6 class ArrayDemo 
 7 {
 8     public static void main(String[] args) 
 9     {
10         Print.println("---------------");
11         int[] a = new int[5];
12         Print.println("a[1] = " + a[1]);
13         Print.println("a[5] = " + a[5]);    //ArrayIndexOutOfBoundsException: 5,but [compile well].
14         Print.println("---------------");
15         a = null;
16         Print.println(a[2]);    //java.lang.NullPointerException,but [compile well].
17     }
18 }

 

posted @ 2014-03-04 19:34  wonkju  阅读(165)  评论(0编辑  收藏  举报