Multiple choice technology

public class Gen<G>{ G g; Gen(G g) { this.g =g; } public static void main(String[] args) { Gen<String> arr[] = new Gen[5]; //line 1 arr[0] = new Gen("Java"); //line 2 arr[1] = new Gen(1); //line 3 arr[2] = (Gen<String>)new Gen(1); //line 4 arr[3] = (Gen<String>)new Gen<Integer>(1); //line 5 for(Gen o:arr) { System.out.println(o); } } }

  1. Compile time Error at line 1

  2. Compile time Error at line 3

  3. Compile time Error at line 4

  4. Compile time Error at line 5

  5. Run Time Error

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

Line 1 compiles (raw type array with warning). Line 3 compiles (raw type assignment). Line 4 compiles (unchecked cast from raw type). Line 5 fails because you cannot cast Gen to Gen - Java disallows conversion between different parameterized generic types even with a cast.