🎙 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 1 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) {
        System.out.println(Size.LARGE.ordinal() + " " + Size.values().length);
    }
}
  1. A.3 3
  2. B.2 3
  3. C.2 2
  4. D.LARGE 3
Answer & explanation

Correct answer: 2 3

ordinal starts at 0, so LARGE is 2; there are 3 constants.

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 →