This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes Regarding assiging a reference to array object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Regarding assiging a reference to array object" Watch "Regarding assiging a reference to array object" New topic
Author

Regarding assiging a reference to array object

Pradeep Kumar
Ranch Hand

Joined: Sep 11, 2007
Posts: 77
Hi,
As we know we can asiign a array boject to a same dimensional array object
For ex: String[] array1 = {"one","two","three"};
String[] array2 = array1;

The above looks obviously simple but is there any metho to check when the same is for a multi dimesional array reference. I get confused when we have something like this. Can someone share a methodology to solve this or tell me an easy shortcut of how to identify the correct version.

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;

Thanks in advance for letting me know how it works.


SCJP 1.6
bart zagers
Ranch Hand

Joined: Feb 05, 2003
Posts: 234
You have given the clue yourself:
As we know we can assign a array object to a same dimensional array object

Start from there, try the different possibilities and see which ones compile. Come back to ask about the ones you don't understand.
 
jQuery in Action, 2nd edition
 
subject: Regarding assiging a reference to array object
 
Similar Threads
Array Dimensions
Can you explain this with code...
Array confusion
Doubt in Multi D Array-Qs 12 Pg 49, K&B
scjp1.4 qtn on Mult-dimensional array