aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Doubt in Multi D Array-Qs 12 Pg 49, K&B Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Doubt in Multi D Array-Qs 12 Pg 49, K&B" Watch "Doubt in Multi D Array-Qs 12 Pg 49, K&B" New topic
Author

Doubt in Multi D Array-Qs 12 Pg 49, K&B

kirti tiwari
Greenhorn

Joined: Feb 04, 2007
Posts: 15
Hi Ranchers....am preparing for SCJP 1.4 and not getting through this question. Please help me out.
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.)


Please do let me know about the approach to go for.
Thanks
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
First of all kirti, welcome to JavaRanch.

Please let us know the options that we are being asked to choose from.

Thanks
-Barry


(Barry:edited out my mistake - question source in title)
[ February 05, 2007: Message edited by: Barry Gaunt ]

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
kirti tiwari
Greenhorn

Joined: Feb 04, 2007
Posts: 15
Hi Barry.
Below are the options to choose from.



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;

Please let me know about thge soln.
thanks
Nirav Patel
Greenhorn

Joined: May 27, 2005
Posts: 22
Hi,
Correct ans: A,B,E,F

Check for the correct dimentions we can assign, means 2d -> 2d, 3d -> 3d, etc...in C & D, assignment is not compatible as dimentions are not same.

Hope this helps.

Regards.


----<br />Nirav Patel<br />Software is the bottleneck in the digital world!
kirti tiwari
Greenhorn

Joined: Feb 04, 2007
Posts: 15
Thanks Nirav.....but still how could you find E?? I am not getting it.....Please help.

Regards
Kirti
paresh doshi
Ranch Hand

Joined: Nov 20, 2006
Posts: 81
Hi,

b2[0][1][0][0] is the single element value of 4d array. And b[0][0] is also the element value of 2d array. So E is also one of the correct answer.

Regards,
Paras


Thanks.<br />Paresh Doshi<br />SCJP 1.4
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Doubt in Multi D Array-Qs 12 Pg 49, K&B
 
Similar Threads
Can you tell me how to answer such question?
multidimensional array question
Multidimensional Arrays
Array confusion
Self Test Question on Arrays by Kathy's Book