Multiple choice technology programming languages

Class C { public static void main(String[] args) { int[]a1[]=new int[3][3]; //3 int a2[4]={3,4,5,6}; //4 int a2[5]; //5 } } What is the result of attempting to compile and run the program ?

  1. compiletime error at lines 3,4,5

  2. compiltime error at line 4,5

  3. compiletime error at line 3

  4. Runtime Exception

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

Line 3 has valid syntax (though unusual). Line 4 is invalid - array declaration syntax is type[] arrayName not type arrayName[size]. Line 5 is invalid - you can't declare array dimensions in the declaration without initialization. The compiler errors on lines 4 and 5.

AI explanation

Line 3 (int[]a1[]=new int[3][3];) is valid Java syntax — using brackets in mixed pre/post-identifier positions to declare a 2D array is legal, if unusual style. Lines 4 and 5, however, both attempt to specify an array's size inside the declaration brackets (int a2[4] and int a2[5]), which is illegal in Java — array sizes can only be specified when using new, not in the type/variable declaration itself, so both lines fail to compile.