Java OCA OCP Practice Question 2111

Question

Choose the correct option based on this program:.

import java.util.*;

public class Main {
     public static void main(String []args) {
         List<int> intList = new ArrayList<>();
         intList.add(10);/*from  w  w  w  . j ava 2s.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