ProgrammingHardProduct-company placement · Java

Which line fails to compile?

Which line fails to compile?
List<String>[] a = new List<String>[2];   // L1
List<?>[] b = new List<?>[2];             // L2
List<String>[] c = new List[2];           // L3
  1. A. L1 and L2
  2. B. L3 only
  3. C. L1 and L3
  4. D. L1 only

Correct answer: D. L1 only

Creating an array of a non-reifiable generic type is forbidden, because the array could not check its element type at run time. Unbounded-wildcard arrays are allowed, and a raw array compiles with an unchecked warning.

More OOP with C++ and Java questions

Exams that ask this topic