Java OCA OCP Practice Question 3172

Question

Predict the output of 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());
     }//  w ww.ja  va  2 s . co m
}
A.   It prints the following://from   ww w . ja  v  a2s .  c om

     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

Due to type erasure, after compilation both types are treated as same LinkedList type.




PreviousNext

Related