Given:
42. void go() { 43. int cows = 0; 44. int[] arr = {1,2,3}; 45. for(int i = 0; i < 4; i++) 46. switch(arr[i]) { 47. case 2: cows++; 48. case 1: cows += 10; 49. case 0: go(); 50. } /* w ww. j ava 2 s . co m*/ 51. System.out.println(cows); 52. }
What is the result?
E is correct.
Because of switch fall-through logic, the go()
method is called recursively until the stack "explodes" (that's the vulgate).
The for loop would fail with option F if it ever got to run to completion.