Site Search:

OCPJP Simulation Test 40

<Back to OCPJP





Question: What is the output of the following program?


  1 public class Node<K, V>{
  2   private V value;
  3   private K key;
  4   private Node<K, V> next;
  5   public Node(K key, V value, Node<K, V> next) {
  6     this.key = key;
  7     this.value = value;
  8     this.next = next;
  9   }
 10   public final K getKey() {return key;}
 11   public final V getValue() { return value;}
 12   public final Node<K, V> getNext() {return next;}
 13   public static void main(String[] args) {
 14     Node<Integer, String> a = new Node<>(1, "10", null);
 15     Node<Integer, String> b = new Node<>(2, "20", a);
 16     System.out.println(b.getValue() +b.getNext().getKey() + b.getNext().getNext());
 17   }}


Choice:
A. compiler error at line 5
B. compiler error at line 12
C. compiler error at line 15
D. compiler error at line 16
E. 201null
F. 20nullnull
G. 202a
H. code compiles but throws exception at runtime