138k views
4 votes
What is the equivalent form of "int[] myArray = new int[5];"? a) int[] myArray[5]; b) myArray = new int[5]; c) int myArray[5]; d) myArray = int[5];

User GDmac
by
7.9k points

1 Answer

6 votes

Final answer:

Option b) myArray = new int[5]; is the equivalent form of the Java array declaration int[] myArray = new int[5]; because it correctly assigns a new integer array of size 5 to the predeclared variable myArray.

Step-by-step explanation:

The equivalent form of the code int[] myArray = new int[5]; in Java is option b) myArray = new int[5];. This is because the statement is simply an assignment without declaring the type since the array myArray has already been declared. Option a) int[] myArray[5]; is incorrect because in Java, array sizes are not specified on the left side of the declaration. Option c) int myArray[5]; is a syntax that resembles C/C++ but is invalid in Java. Lastly, option d) myArray = int[5]; lacks the new keyword that is required to create a new array instance in Java.