Java OCA OCP Practice Question 2138

Question

What is the result of the following?.

Map<String, String> map = new TreeMap<>(); 
map.put("tool", "HTML"); 
map.put("problem", "Web"); 


Property props = new Property();          // p1 
map.forEach((k,v) -> props.put(k, v));    // p2 


String t = props.getProperty("tool");     // p3 
String n = props.getProperty("Web"); 
System.out.println(t + " " + n); 
  • A. HTML Web
  • 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.


B.

Note

The class on line p1 should be Properties rather than Property.

As written it is incorrect and does not compile, making Option B the answer.




PreviousNext

Related