Difficulty: Easy
Correct Answer: int[] ia = new int[15];
Explanation:
Introduction / Context:
Array creation in Java requires the new operator with proper brackets. This question asks you to identify which statement both declares and allocates an array.
Given Data / Assumptions:
Concept / Approach:
An array is an object. The allocation is explicit via new Type[dimension] or implicit via an initializer list like { ... } with properly nested braces. Type compatibility must also be correct.
Step-by-Step Evaluation:
int[] ia = new int[15]; → correct; allocates an int array of length 15.B: float fa = new float[20]; → invalid; left-hand side is a scalar float, not an array.C: char[] cannot be directly assigned from a String literal; requires "Some String".toCharArray().D: 2D initializer syntax is malformed; needs nested braces: int[][] ia = { {4,5,6}, {1,2,3} };.E: This line merely declares; it does not allocate any array.
Verification / Alternative check:
Compiling each statement in isolation confirms A as the only definitely allocating statement.
Why Other Options Are Wrong:
They are either syntactically incorrect or do not allocate an array object.
Common Pitfalls:
Mistaking declarations or malformed initializers for actual allocation; ignoring type mismatches.
Final Answer:
int[] ia = new int[15];
Discussion & Comments