Java OCA OCP Practice Question 3170

Question

Predict the output of this program:

import java.util.*;

public class Main {
     public static void main(String []args) {
             List<int> intList = new ArrayList<>();
             intList.add(10);/*  w  w  w.j  av  a2  s  . c o  m*/
             intList.add(20);
             System.out.println("The list is: " + intList);
     }
}
  • A. It prints the following: The list is: [10, 20].
  • B. It prints the following: The list is: [20, 10].
  • C. It results in a compiler error.
  • D. It results in a runtime exception.


C.

Note

You cannot specify primitive types along with generics, so List<int> needs to be changed to List<Integer>.




PreviousNext

Related