Site Search:

OCPJP Simulation Test 48

<Back to OCPJP





What is the output of the following program?

  1 import java.util.*;
  2 public class Fruits{
  3   public static void print1(List<?> list) {
  4     System.out.print("1" + list.size());
  5     System.out.print(list);}
  6   public static <T>void print2(List<? extends T> list) {
  7     System.out.print("2" + list.size());
  8     System.out.print(list);}
  9   public static <T>void print3(List<? super T> list) {
 10     System.out.print("3" + list.size());
 11     System.out.print(list);}
 12   public static void main(String[] args) {
 13     List<String> fruits = new ArrayList<>();
 14     fruits.add("pearl");
 15     print1(fruits);
 16     print2(fruits);
 17     print3(fruits);}}

Choice:
A. 11[pearl]21[pearl]31[pearl]
B. 11pearl21pearl31pearl
C. 11[pearl]21[pearl]
D. 11[pearl]
E. compiler error at line 6
F. compiler error at line 9
G. compiler error at other lines
H. code throws runtime exception