Site Search:

OCPJP Simulation Test 94

<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     System.out.print(s1.get().add("xyz"));
  7     System.out.print(s1.get());
  8     Supplier<Map<Integer, String>> s2 = TreeMap::new;
  9     System.out.print(s2.get());}}


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