Java Programming - Declarations and Access Control - Discussion

Discussion Forum : Declarations and Access Control - General Questions (Q.No. 13)
13.
Which one creates an instance of an array?
int[ ] ia = new int[15];
float fa = new float[20];
char[ ] ca = "Some String";
int ia[ ] [ ] = { 4, 5, 6 }, { 1,2,3 };
Answer: Option
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.

Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.