Which cause a compiler error?
a. int[ ] scores = {3, 5, 7};
b. int [ ][ ] scores = {2,7,6}, {9,3,45};
c. string cats[ ] = {"fluffy", "spot", "zeus"};
d. boolean results[ ] = new boolean [] {true, false, true};
e. integer results[ ] = {new integer(3), new integer(5), new integer(8)};?
Answers
Answered by
9
The following are valid initializations in Java.
a. int[ ] scores = {3, 5, 7}; #integer array
c. String cats[ ] = {"fluffy", "spot", "zeus"}; #String array
d. boolean results[ ] = new boolean [] {true, false, true}; # boolean array
e. Integer results[ ] = {new Integer(3), new Integer(5), new Integer(8)}; # Integer array
But the initialization
b. int [ ][ ] scores = {2,7,6}, {9,3,45}; is incorrect. The correct initialization is
int [ ][ ] scores = {{2,7,6}, {9,3,45}};
Hence (b) causes a compile time error.
Answered by
0
Answer:
B is the correct answer in the following
Similar questions