Home » Java Programming » Declarations and Access Control

Which cause a compiler error?

Correct Answer: int [ ][ ] scores = {2,7,6}, {9,3,45};

Explanation:

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} };





← Previous Question Next Question→

More Questions from Declarations and Access Control

Discussion & Comments

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