Multiple choice technology architecture

public class Gen { G g; Gen(G g) { this.g =g; } public static void main(String[] args) { Gen arr[] = new Gen[5]; //line 1 arr[0] = new Gen("Java"); //line 2 arr[1] = new Gen(1); //line 3 arr[2] = (Gen)new Gen(1); //line 4 arr[3] = (Gen)new Gen(1); //line 5 for(Gen o:arr) { System.out.println(o); } } } what is the output of the above code?

  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 5 causes a compile-time error: you cannot cast Gen to Gen because generic types are invariant. Even though type erasure means both become Gen at runtime, the compiler enforces type safety. The cast (Gen)new Gen(1) is trying to convert one generic type to another incompatible generic type, which the compiler rejects. Line 4's raw Gen cast is allowed (unchecked warning), line 3's unparameterized Gen(1) matches the raw array, and line 1's raw array creation is legal.