🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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);
    }
}
  1. A.3
  2. B.LARGE3
  3. C.5
  4. 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 →