Multiple choice technology programming languages

List l = new Arraylist(); if you use this line in your code what will we get?

  1. Runtime error.

  2. Depends on the code where you use

  3. Compiles Fine

  4. Compilation error.

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

In Java, generics are invariant. A List reference cannot be assigned an ArrayList instance because a List is not a supertype of List. This mismatch results in a compilation error.