Given the following, 1. public class Test { 2. public static void main(String [] args) { 3. byte [][] big = new byte [7][7]; 4. byte [][] b = new byte [2][1]; 5. byte b3 = 5; 6. byte b2 [][][][] = new byte [2][3][1][2]; 7. 8. } 9. } which of the following lines of code could be inserted at line 7, and still allow the code to compile? (Choose four that would work.) A. b2[0][1] = b; B. b[0][0] = b3; C. b2[1][1][0] = b[0][0]; D. b2[1][2][0] = b; E. b2[0][1][0][0] = b[0][0]; F. b2[0][1] = big;
I would like to know the set of answers for the above question along with an explanation as to why.
karthikeyan Chockalingam
Ranch Hand
Joined: Sep 06, 2003
Posts: 259
posted
0
Option C and D that is will not compile as the assigned array dimensions are not compatible .
If you have a computer with the JDK installed, you can find out for yourself which of the answers is correct.
A hint: Multi-dimensional arrays in Java are just arrays of arrays. So byte[][] b is an array of arrays: the entries b[0], b[1], ... are each an array of bytes (byte[]).
byte[][][][] b2 is an array of arrays of arrays of arrays. b2[0] is a byte[][][]. b2[0][0] is a byte[][]. b2[0][0][0] is a byte[]. b2[0][0][0][0] is a byte.