What would be the output from this code fragment?
1. int x = 0, y = 4, z = 5; 2. if (x > 2) { 3. if (y < 5) { 4. System.out.println("message one"); 5. } //from ww w. j a v a 2 s .c om 6. else { 7. System.out.println("message two"); 8. } 9. } 10. else if (z > 5) { 11. System.out.println("message three"); 12. } 13. else { 14. System.out.println("message four"); 15. }
D.
The first test at line 2 fails, which immediately causes control to skip to line 10.
It is bypassing both the possible tests that might result in the output of message one or message two.
At line 10, the test is again false, so the message at line 11 is skipped.
Message four, at line 14, is output.