Win a copy of Functional Reactive Programming this week in the Other Languages forum!

# Master Exam Array question

AustinRay Lee
Greenhorn
Posts: 3
Can someone explain the answer to this problem, master exam says that answer C below "is wrong because C tries to assign a two-dimensional array where a one-dimensional array is expected." I can see that b is a two-dimensional array, but it looks like b2 is four-dimensional array. So I would expect the answer to say "C is wrong because C tries to assign a two-dimensional array where a four-dimensional array is expected." Or why is b2 considered a one-dimensional array when it has 4 []'s.
public class Test{
public static void main(String [] args){
short [][] b = new short [4] [4];
short [][]big = new short [2][2];
short b3 = 8;
short b2 [][][][] = new short [2][3][2][2];
// insert code here
}
}
A b2[1][1] = big;
B b[1][0] = b3;
C b2[0][1][1] = b:

Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
Let's start simple and build up ...

Whew. Looks like what you can put into any slot is enough dimensions to fill out the original declaration. In "a[1]" that means no more dimensions, only an int. In d[1][1][1] as in your question, only one more dimension.