Oracle
1Z0-851 · Question #41
Which two code fragments are most likely to cause a StackOverflowError? (Choose two.)
The correct answer is D. void doOne(int x) { doTwo(x); } void doTwo(int y) { doThree(y); } void doThree(int z) { doTwo(z); } F. void counter(int i) { counter(++i); }. See the full explanation below for the reasoning.
Question
Which two code fragments are most likely to cause a StackOverflowError? (Choose two.)
Options
- Aint []x = {1,2,3,4,5}; for(int y = 0; y < 6; y++) System.out.println(x[y]);
- Bstatic int[] x = {7,6,5,4}; static { x[1] = 8; x[4] = 3; }
- Cfor(int y = 10; y < 10; y++) doStuff(y);
- Dvoid doOne(int x) { doTwo(x); } void doTwo(int y) { doThree(y); } void doThree(int z) { doTwo(z); }
- Efor(int x = 0; x < 1000000000; x++) doStuff(x);
- Fvoid counter(int i) { counter(++i); }
How the community answered
(35 responses)- B6% (2)
- C3% (1)
- D83% (29)
- E9% (3)
Community Discussion
No community discussion yet for this question.