Declarations and Access Control

Q1: Which one creates an instance of an array?

A float fa = new float[20];

B int ia[ ] [ ] = { 4, 5, 6 }, { 1,2,3 };

C char[ ] ca = "Some String";

D int[ ] ia = new int[15];

ANS:A - int[ ] ia = new int[15];

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.



img not found
img

For help Students Orientation
Mcqs Questions

One stop destination for examination, preparation, recruitment, and more. Specially designed online test to solve all your preparation worries. Go wherever you want to and practice whenever you want, using the online test platform.