"SCJP 1.6版考題 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]); ...) |
(無差異)
|
於 2013年3月30日 (六) 03:22 的最新修訂
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: D F
解說:
此題問那個敘述最可能發生StackOverflowError 堆疊溢位錯誤 D 是doTwo和doThree二個方法間無條件地呼叫彼此(間接遞迴),沒有停止條件,一個方法若無盡地被呼叫, 會持續在呼叫堆疊中配置出所需要方法變數空間,一直到堆疊空間滿了(堆疊溢出) F 也是同樣的意思 無條件式的直接遞迴,沒有停止…
| ||||||||||||||||||||