Site Search:

OCPJP Simulation Test 95

<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     System.out.print(s2.get());}}


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