🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← All practice quizzes

Quiz: Java Enums

Read all questions with answers & explanations →

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

A Java enum is not just a list of names. Each constant is a full object that can have fields, a constructor and methods, and even its own version of a method. Learn enums the object-oriented way, with EnumMap and EnumSet.

Log in to take the quiz

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

  1. Question 1

    What is the main advantage of an enum over int constants?

  2. Question 2

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

    Which statement about an enum's constructor is true?

  4. Question 4

    What happens with Day.valueOf("sun") when the constant is declared as SUN?

  5. Question 5

    What does this print?

    enum Coin {
        ONE(1), TWO(2), 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 + " " + Coin.FIVE.ordinal());
        }
    }
    
🎯 Today’s placement challenge — 10 questions, no login. Can you score 10/10?6 students have taken today’s challengeTake today’s challenge →