Site Search:

OCPJP Simulation Test 34

<Back to OCPJP





Question: What's are the outputs of the following program?


  1 public class Box<T> {
  2   private T contents;
  3   public Box(T t) {
  4     contents = t;
  5   }
  6   public T getContents() {
  7     return contents;
  8   }
  9   public void setContents(T t) {
 10     contents = t;
 11   }
 12   public static void main(String args[]) {
 13     Box<String> box = new Box<String>("gift");
 14     System.out.println(box.getContents());
 15 
 16     Box<Integer> box2 = new Box<>(5);  
 17     System.out.println(box2.getContents() instanceof Integer);
 18   }
 19 }


Choice:
A. gift
B. null
C. 0
D. true
E. false
F. 5
G. The code does not compile
H. The code compiles but throw run time exceptions