SCJP題庫第113題

Given:
10. public class Foo{
11.   static int[] a;
12.   static{ a[0] = 2;}
13.   public static void main( String[] args){}
14. }
Which exception or error will be thrown when a programmer attempts to run this code?




A. java.lang.StackOverflowError
B. java.lang.IllegalStateException
C. java.lang.ExceptionInInitializerError
D. java.lang.ArrayIndexOutOfBoundsException

Ans: C

解說:
static初始區塊發生錯誤會跑出java.lang.ExceptionInInitializerErrora[0]存取一個不存在的陣列物件而發生錯誤!

Comments

Popular posts from this blog

Android+Google Map API v3 Geocoding(地址轉經緯度度