ProgrammingModerateProduct-company placement · Java

What is printed?

What is printed?
enum Day { MON, TUE, WED }
// in main:
Map<Day, Integer> m = new EnumMap<>(Day.class);
m.put(Day.WED, 3);
m.put(Day.MON, 1);
System.out.print(m);
  1. A. {MON=1, WED=3}
  2. B. {WED=3, MON=1}
  3. C. {MON=1, TUE=null, WED=3}
  4. D. {1=MON, 3=WED}

Correct answer: A. {MON=1, WED=3}

An EnumMap keeps its keys in the natural order of the enum constants (declaration order), regardless of insertion order, and only contains the keys that were put.

More OOP with C++ and Java questions

Exams that ask this topic