Java OCA OCP Practice Question 2729

Question

What is the result of the following code?

4: Map m = new HashMap();  
5: m.put(123, "456");  
6: m.put("abc", "def");  
7: System.out.println(m.contains("123"));  
  • A. false
  • B. true
  • C. Compiler error on line 4.
  • D. Compiler error on line 5.
  • E. Compiler error on line 7.
  • F. A runtime exception is thrown.


E.

Note

This question looks like it is about generics, but it's not.

It is trying to see if you noticed that Map does not have a contains() method.

It has containsKey() and containsValue() instead.

If containsKey() was called, the answer would be false because the 123 in the list is an Integer rather than a String.




PreviousNext

Related