Multiple choice technology programming languages

Which are legal declarations? (Choose all that apply. )

  1. short x [];

  2. short [] y;

  3. short [5] x2;

  4. short z2 [5];

  5. short [] z [] [];

  6. short [] y2 = [5];

Reveal answer Fill a bubble to check yourself
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.