1z0-829 Exam QuestionsBrowse all questions from this exam

1z0-829 Exam - Question 21


Given the code fragment:

What is the result?

Show Answer
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

2 comments
Sign in to comment
zuluitaiOption: D
Jun 12, 2024

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

xplorerpjOption: D
Jun 24, 2024

D is correct answer