Site Search:

OCPJP Simulation Test 51

<Back to OCPJP





What is the output of the following program?

  1 import java.util.*;
  2 public class Fruits<T>{
  3   public void print1(List<?> list) {
  4     System.out.print("1" + list.size());
  5     System.out.print(list);}
  6   public static void <T> print2(List<? extends T> list) {
  7     System.out.print("2" + list.size());
  8     System.out.print(list);}
  9   public static void <T> 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     Fruits<String> f = new Fruits<>();
 14     List<String> fruits = new ArrayList<>();
 15     fruits.add("pearl");
 16     f.print1(fruits);
 17     f.print2(fruits);
 18     f.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