← Quiz: Java Enums: all 10 questions
Quiz: Java Enums · Question 2 of 10
What does this print? (code)
What does this print?
enum Size { SMALL, MEDIUM, LARGE }
public class Main {
public static void main(String[] args) {
Size s = Size.valueOf("LARGE");
System.out.println(s.ordinal() + Size.values().length);
}
}
- A.3
- B.LARGE3
- C.5
- D.6
Answer & explanation
Correct answer: 5
LARGE has ordinal 2 and there are 3 constants: 2 + 3 = 5.
Can you get the rest right without peeking?
Take the timed Quiz: Java Enums quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →