Java OCA OCP Practice Question 2108

Question

What is the result of the following?.

Map<String, String> map = new TreeMap<>(); 
map.put("tool", "HTML"); 
map.put("problem", "Markup"); 
  
Properties props = new Properties();      // p1 
map.forEach((k,v) -> props.put(k,  v));   // p2 
  
String t = props.get("tool");             // p3 
String n = props.get("Markup"); 
System.out.println(t + " " + n); 
  • A. HTML Markup
  • B. The code does not compile due to line p1.
  • C. The code does not compile due to line p2.
  • D. The code does not compile due to line p3.


D.

Note

The Properties class implements Map.

While the get() method, inherited from the superclass, is available, it returns an Object.

Since Object cannot be cast to String, it does not compile, and Option D is the answer.




PreviousNext

Related