File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Master Exam Array question

 
AustinRay Lee
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic