Exam 1z0-829 All QuestionsBrowse all questions from this exam
Question 21

Given the code fragment:

What is the result?

    Correct Answer: D

    The given code uses the new syntax of the switch statement introduced in Java 12, where each case can handle multiple values separated by commas, and the '->' syntax is used. The variable 'rank' is set to 4. When the switch statement evaluates 'rank' with the value 4, it matches the first case '1, 4', which results in printing 'Range1'. No further cases are evaluated after a match is found. Therefore, the output is 'Range1'.

Discussion
xplorerpjOption: D

D is correct answer

zuluitaiOption: D

new syntax of the switch does not require a break statement hence answer is D