Java OCA OCP Practice Question 2110

Question

What is the result of the following?.

Map<Object, Object> 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.getProperty("tool");     // p3 
String n = props.getProperty("problem"); 
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.


A.

Note

This code creates a Map with two elements.

Then it copies both key/value pairs to a Properties object.

This works because a Properties object is also a Map and therefore has a put() method that takes Object parameters.

The code gets the String property values of both keys and prints HTML Markup.

Therefore, Option A is correct.




PreviousNext

Related