What is the result?
A. 9 10 d
B. 8 9 10 d
C. 9 10 10 d
D. 9 10 10 d 13
E. 8 9 10 10 d 13
F. 8 9 10 9 10 10 d 13
G. Compilation fails
Answer:
D is correct. Did you catch the static initializer block? Remember that switches work on
"fall-thru" logic, and that fall-thru logic also applies to the default case, which is used when
no other case matches.
A, B, C, E, F, and G are incorrect based on the above.
Please tell how D is correct...???
According to me in line 3 we have declared a static variable x=7, then we have used a for loop,so according to the for loop it will run thrice,so the value of x will be increased 3 times, as we run the loop first time the value is increased from 7 to 8 and matched with switch (case 8) so first 8 should be printed....but the answer is 9 10 10 d 13....please explain where i am wrong....also tell why 10 is printed twice....???