Site Search:

OCPJP Simulation Test 20

<Back to OCPJP





Question: What is the output of the following code?


  1 import java.util.*;
  2 public class test{
  3  public static void main(String...args) {
  4    List<String> list = new ArrayList();
  5    list.add("str");
  6    list.add("str2");
  7    System.out.println((String)list.get(0));
  8  }
  9 }


Choice:
A. str
B. 10
C. compiler error at line 4
D. compiler error at line 5
E. compiler error at line 6
F. compiler error at line 7
G. code compiles but throws runtime exception