Java OCA OCP Practice Question 2113

Question

Choose the correct option based on this program:.

import java.util.*;

public class Main {
     public static void main(String []args) {
         List<Integer> intList = new LinkedList<>();
         List<Double> dblList = new LinkedList<>();
         System.out.println("First type: " + intList.getClass());
         System.out.println("Second type:" + dblList.getClass());
     }//from  w w  w . j a v a  2s. c om
}
a .  it prints the following://w w w.  ja v a 2  s.com

     First type: class java.util.linkedlist
     second type:class java.util.linkedlist

B.   it prints the following:

     First type: class java.util.linkedlist<integer>
     second type:class java.util.linkedlist<double>

C.   it results in a compiler error

d.   it results in a runtime exception


A.

Note

  • First type: class java.util.linkedlist
  • second type:class java.util.linkedlist
  • due to type erasure, after compilation both types are treated as same LinkedList type.



PreviousNext

Related