Question 5
Back to Exercise
The program below does not compile. Which statement correctly describes the problem?
public class Main {
public static void main(String[] args) {
long id = 3L;
switch (id) {
case 1L -> System.out.println("admin");
case 3L -> System.out.println("guest");
default -> System.out.println("user");
}
}
}
- A Arrows are not allowed in statements
- B long is not a permitted selector type for constant case labels; use int, or if/else for long values Correct
- C default must be last
- D id must be final
Correct Answer: Option B
The same is true for float, double and boolean.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!