Declarations and Access Control

Q1: Which cause a compiler error?

A Integer results[ ] = {new Integer(3), new Integer(5), new Integer(8)};

B String cats[ ] = {"Fluffy", "Spot", "Zeus"};

C boolean results[ ] = new boolean [] {true, false, true};

D int [ ][ ] scores = {2,7,6}, {9,3,45};

E int[ ] scores = {3, 5, 7};

ANS:B - int [ ][ ] scores = {2,7,6}, {9,3,45};

Option B generates a compiler error: <identifier> expected. The compiler thinks 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 one 3 x 3 two-dimensional array. To correct the problem and make option B compile you need to add an extra pair of curly brackets: int [ ] [ ] scores = { {2,7,6}, {9,3,45} };

img not found

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.