Multiple choice technology programming languages

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

  1. Compilation error.

  2. Runtime error

  3. Compiles Fine

  4. Depends on the code where you use

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

This code has a type mismatch - List expects Object elements, but ArrayList can only contain Strings. In Java generics, you cannot assign a more specific generic type (ArrayList) to a more general reference (List) because it would allow type violations at compile time.

AI explanation

This code has a generic type mismatch: 'List l' declares a reference of type List, but it's being assigned 'new Arraylist()' — besides 'Arraylist' not even being valid capitalization for java.util.ArrayList, generics in Java are invariant (ArrayList is not a subtype of List), so the assignment fails type-checking. This mismatch is caught by the compiler, not at runtime, producing a compilation error rather than compiling fine or throwing a runtime exception.