Which are legal declarations?
-
short x [];
-
short [] y;
-
short [5] x2;
-
short z2 [5];
-
short [] z [] [];
-
short [] y2 = [5];
A,B,E
Correct answer
Explanation
In Java, array declarations can place brackets before or after the variable name. A (short x[]) and B (short [] y) are both valid legal declarations. E (short [] z [] []) is valid for multi-dimensional arrays (jagged array declaration). C (short [5] x2) and F (short [] y2 = [5]) are invalid - size cannot be specified in declaration, and array initialization needs 'new short[5]' not '[5]'. D (short z2[5]) is also invalid for same reason as C.