Site Search:

OCPJP Simulation Test 93

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


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