Java Programming
primer-original-v2easyJavaArrayData Typesprimer-original-v2

Which is a valid way to declare and initialize an array in Java?

Answer options

A
int[] arr = new int[5];
B
int arr[] = new int[];
C
int[] arr = new int(-1);
D
int arr = new int[5];

Correct answer: int[] arr = new int[5];

Explanation

Quick AnswerThe correct answer is int[] arr = new int[5]; because it directly addresses the core logic of Java Programming.

This question has been retained as-is due to its unique context.

Related Java Programming questions

Practice more Java Programming questions

PrimerPrep has independently reviewed practice questions and coding exercises — all free.