Skills101
← All practice quizzes

Quiz: Java Enums

5 questions · new set on every retakeNo time limitPass: 60%+10 XP on first pass

Replace magic numbers and strings with enums. values(), valueOf(), ordinal(), switch on an enum, enums with fields and constructors, constant-specific methods, EnumMap and EnumSet.

Log in to take the quiz

Free account · see your score, answers and explanations, earn XP

  1. Question 1

    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);
        }
    }
    
  2. Question 2

    What is the main advantage of an enum over int constants for a method parameter?

  3. Question 3

    What does Status.valueOf("shipped") do if the constant is named SHIPPED?

  4. Question 4

    What does this print?

    enum Coin {
        ONE(1), FIVE(5), TEN(10);
        final int value;
        Coin(int value) { this.value = value; }
    }
    public class Main {
        public static void main(String[] args) {
            int total = 0;
            for (Coin c : Coin.values()) total += c.value;
            System.out.println(total);
        }
    }
    
  5. Question 5

    Which statement about an enum constructor is true?

🎯 Today’s placement challenge — 10 questions, no login. Can you score 10/10?Take today’s challenge →