Question 3
Back to Exercise
What is the output of the following Java program?
enum Level {
LOW, MID, HIGH;
Level() { System.out.print("init " + name() + " "); }
}
public class Main {
public static void main(String[] args) {
System.out.print("start ");
Level a = Level.HIGH;
Level b = Level.LOW;
System.out.println("| " + a + " " + b);
}
}
- A start init LOW init MID init HIGH | HIGH LOW Correct
- B init LOW init MID init HIGH start | HIGH LOW
- C start init HIGH init LOW | HIGH LOW
- D start | HIGH LOW
Correct Answer: Option A
All constants are created, in order, when the enum class is first used – and never again.
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!