SCJP題庫第138題

Which two code fragments are most likely to cause a StackOverflowError? (Choose two.)
A. int[] x = {1, 2, 3, 4, 5};
for(int y=0; y<6; y++)
System.out.println(x[y]);
B. static int[] x = {7, 6, 54};
static{x[1] = 8; x[4] = 3;}
C. for(int y=10; y<10; y++)
doStuff(y);
D. void doOne(int x){doTwo(x);}
void doTwo(int y){doThree(y);}
void doThree(int z){doTwo(z);}
E. for(int x=0; x<1000000000; x++)
doStuff(x);
F. void counter(int i){counter(++i);}

Ans: DF

解說
此題問那個敘述最可能發生StackOverflowError 堆疊溢位錯誤
DdoTwodoThree二個方法間無條件地呼叫彼此(間接遞迴),沒有停止條件,一個方法若無盡地被呼叫,會持續在呼叫堆疊中配置出所需要方法變數空間,一直到堆疊空間滿了(堆疊溢出)
F也是同樣的意思 無條件式的直接遞迴,沒有停止

Comments

Popular posts from this blog

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