Which are legal declarations? (Choose all that apply. )
-
short x [];
-
short [] y;
-
short [5] x2;
-
short z2 [5];
-
short [] z [] [];
-
short [] y2 = [5];
A,B,E
Correct answer
Explanation
Java allows multiple array declaration syntaxes: brackets can go before or after the variable name. Option A (short x[]) places brackets after name - valid. Option B (short [] y) places brackets before name - valid. Option E (short [] z [] []) is valid 3D array syntax. Options C and D are invalid because array sizes cannot be specified in declaration - only during initialization with 'new'. Option F is invalid because initialization requires 'new short[5]' syntax.