Java OCA OCP Practice Question 1575

Question

Which cannot fill in the blank for this code to compile?

Collection<String> c = new ___ <>();
c.add("A");
c.remove("A");
System.out.println(c.isEmpty());
  • A. ArrayDeque
  • B. TreeMap
  • C. TreeSet
  • D. All of these can fill in the blank.


B.

Note

Java talks about the collections framework, but the Map interface does not actually implement the Collection interface.

TreeMap has different methods than ArrayDeque and TreeSet.

It cannot fill in the blank, so Option B is correct.




PreviousNext

Related