Site Search:

OCPJP Simulation Test 46

<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<Object> list) {
  4     System.out.print("1" + list.size());}
  5   public static void print2(List<?> list) {
  6     System.out.print("2" + list.size());
  7     for(Object obj: list) {System.out.println(obj);}}
  8   public static <T>void print3(List<T> list) {
  9     System.out.println("3" + list.size());
 10     for(T t: list) {System.out.println(t);}}
 11   public static void main(String[] args) {
 12     List<String> fruits = new ArrayList<>();
 13     fruits.add("apple");
 14     print1(fruits);
 15     print2(fruits);
 16     print3(fruits);}}

Choice:
A. 1121apple31apple
B. 1121obj31t
C. compiler error at line 3
D. compiler error at line 5
E. compiler error at line 8
F. compiler error at line 14
G. compiler error at line 15
H. compiler error at line 16