Given the code fragment:
What is the result?
Given the code fragment:
What is the result?
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'.
D is correct answer
new syntax of the switch does not require a break statement hence answer is D