Question:medium

Which of the following is a valid declaration of a Java array?

Show Hint

In Java, there are two syntactically correct ways to declare an array reference: `type[] arrayName;` (preferred) and `type arrayName[];` (C/C++ style). But instantiation always requires `new type[size]`.
Updated On: Jul 2, 2026
  • int arr[] = new int[];
  • int arr = new int[5];
  • int arr[] = new int[5];
  • int arr[] = new int(5);
Show Solution

The Correct Option is C

Solution and Explanation

Step 1: Recall the two-part nature of a Java array.
Creating a usable array in Java needs a reference variable to point to it and an actual array object built with new, and both parts have to follow strict syntax rules.
Step 2: Check the reference declaration part.
Writing int arr[], or equally int[] arr, correctly declares arr as a reference capable of pointing to an array of integers, whereas plain int arr declares only a single integer variable, not an array reference at all.
Step 3: Check the object creation part.
The new int[5] portion is what actually allocates space for 5 integers, and this size must be given inside square brackets, never left blank and never placed inside parentheses, so only the option using new int[5] with square brackets satisfies both requirements together.
\[ \boxed{\text{int arr[] = new int[5];}} \]
Was this answer helpful?
0