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?

  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 attempts to cast a Gen to Gen. While line 4's raw type cast compiles with a warning, line 5 is a compile-time error because you cannot directly cast a parameterized type of one generic type to another. The compiler enforces type safety - Gen and Gen are incompatible types. The error occurs at compile time because generics are erased but type checking happens during compilation to ensure type safety.