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);- A. {MON=1, WED=3}
- B. {WED=3, MON=1}
- C. {MON=1, TUE=null, WED=3}
- 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
- Which line fails to compile? java List<String>[] a = new List<String>[2]; // L1 List<?>[] b = new List<?>[2]; // L2 List<String>[] c = new…
- Which line fails to compile? java class Box<T extends Number> { double d(T t) { return t.doubleValue(); } } // in main: Box<Integer> a =…
- Which class compiles? java class K1 { static { throw new RuntimeException(); } } class K2 { static { if (true) throw new…
- What happens? java class W { { if (true) throw new java.io.IOException("io"); } W() throws java.io.IOException { } }
- Which line fails to compile? cpp // C++17 struct S { int v; S(int x) : v(x) { } bool operator==(const S& o) const { return v == o.v; } }…
- What is printed? cpp struct B { void run() { step(); } virtual void step() { cout << "B"; } }; struct D : B { void step() override { cout…