Question:

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
collegedunia
Verified By Collegedunia

The Correct Option is C

Solution and Explanation

In Java, arrays are objects that store a fixed-size sequential collection of elements of the same type. Array declaration and instantiation involve specific syntax.
The general syntax is: `type var-name[] = new type[size];`
Let's analyze the options:
(A) `int arr[] = new int[];`: This is invalid. When you instantiate an array using `new`, you must provide a size inside the square brackets.
(B) `int arr = new int[5];`: This is invalid. The declaration `int arr` defines a simple integer variable, not an array reference. It should be `int[] arr` or `int arr[]`.
(C) `int arr[] = new int[5];`: This is a valid declaration. `int arr[]` declares `arr` as a reference to an integer array. `new int[5]` creates a new array object in memory that can hold 5 integers and assigns its reference to `arr`. The alternative syntax `int[] arr = new int[5];` is also valid and often preferred.
(D) `int arr[] = new int(5);`: This is invalid. The size of the array is specified using square brackets `[]`, not parentheses `()`. Parentheses are used for constructor calls.
Was this answer helpful?
0
0