Site Search:

OCPJP Simulation Test 100

<Back to OCPJP





Question: What is the output of the following code?

  1 import java.util.function.*;
  2 import java.util.*;
  3 public class Printing {
  4   public static void main(String...args) {
  5     Supplier<Set<String>> s1 = HashSet::new;
  6     Set<String> s = s1.get();
  7     System.out.print(s.add("xyz"));
  8     System.out.print(s);
  9     Supplier<Map<Integer, String>> s2 = TreeMap::new;
 10     Map<Integer, String> m = s2.get();
 11     m.put(10, "xyz");
 12     System.out.print(m.put(10, "xxx"));}}


Choice:
A. program print nothing
B. [][]{}
C. [xyz][xyz]{10=xxx}
D. true[xyz]true
E. true[xyz]{10=xyz}
F. true[xyz]xyz
G. code does not compile
H. code compiles but throw runtime exceptions.