← Quiz: Java Enums: all 10 questions
Quiz: Java Enums · Question 8 of 10
What does this print? (code)
What does this print?
import java.util.*;
enum Day { MON, TUE, WED }
public class Main {
public static void main(String[] args) {
Map<Day, String> m = new EnumMap<>(Day.class);
m.put(Day.WED, "test");
m.put(Day.MON, "class");
System.out.println(m);
}
}
- A.{WED=test, MON=class}
- B.{MON=class, WED=test}
- C.{class, test}
- D.Error: EnumMap needs all keys
Answer & explanation
Correct answer: {MON=class, WED=test}
EnumMap always keeps keys in declared order, whatever order you insert them.
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 →