Home » Java Programming » Declarations and Access Control

Which one creates an instance of an array?

Correct Answer: int[ ] ia = new int[15];

Explanation:

Option A is correct. It uses correct array declaration and correct array construction.


Option B is incorrect. It generates a compiler error: incompatible types because the array variable declaration is not correct. The array construction expects a reference type, but it is supplied with a primitive type in the declaration.


Option C is incorrect. It generates a compiler error: incompatible types because a string literal is not assignable to a character type variable.


Option D is wrong, it generates a compiler error <identifier> expected. The compiler thinks that you are trying to create two arrays because there are two array initialisers to the right of the equals, whereas your intention was to create a 3 x 3 two-dimensional array.


← Previous Question Next Question→

More Questions from Declarations and Access Control

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion