aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes scjp1.4 qtn on Mult-dimensional array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "scjp1.4 qtn on Mult-dimensional array" Watch "scjp1.4 qtn on Mult-dimensional array" New topic
Author

scjp1.4 qtn on Mult-dimensional array

Muthuvel Ramamoorthy
Greenhorn

Joined: Jun 08, 2006
Posts: 20
Hi,

The answer for the following question is A, B, E, and F.
Could you please any one explain, how these answers are correct?

Thank you

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;
Naseem Khan
Ranch Hand

Joined: Apr 25, 2005
Posts: 809
a, b, e, f is correct.
[ June 08, 2006: Message edited by: Naseem Khan ]

Asking Smart Questions FAQ - How To Put Your Code In Code Tags
lavanya sankuappan
Greenhorn

Joined: Jun 02, 2006
Posts: 17
how come option c is wrong while e works fine?
wise owen
Ranch Hand

Joined: Feb 02, 2006
Posts: 2023
C. b2[1][1][0] = b[0][0];
"b[0][0]" is byte.

F. b2[0][1] = big;
"big" is two dimensional array.
Naseem Khan
Ranch Hand

Joined: Apr 25, 2005
Posts: 809


Option C->>> required is one dimentional array but found primitive type.

Option E->>> required is primitive type type and found same.
lavanya sankuappan
Greenhorn

Joined: Jun 02, 2006
Posts: 17
thanks for your response guys
sree latha
Greenhorn

Joined: Jun 08, 2006
Posts: 3
Hi,

if you guys dont mind can u please explain the correct answers once again

thanks
sreelatha
Naseem Khan
Ranch Hand

Joined: Apr 25, 2005
Posts: 809




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;


A. b2[0][1]is two dimentional array and b is also 2-D array. TRUE

B. b[0][0] is primitive byte and b3 is alos primitive byte. Same type. TRUE

C. b2[1][1][0] is one dimentional array and b[0][0] is primitive type. Incompatible type. FALSE.

D. b2[1][2][0] is one dimentional array and b is 2-D array. Incompatible type. FALSE

E. b2[0][1][0][0] is byte primitive type and b[0][0] is also byte primitive type. TRUE

F. b2[0][1] is 2-D array and big is also 2-D array. So compatible type. TRUE

regards
warren li
Ranch Hand

Joined: May 23, 2006
Posts: 128
I have a doubt here. E.g. answer E:
F. b2[0][1] = big;

b2 has already specified the sizes of its 4 dimensions.
and b2[0][1] will have size [1][2].
but big's size is [7][7] which is larger than b2[0][1].

how can 'big' fit into b2[0][1]? Or is this checked in run time but not in compile time? isn't array's size already known at compile time?


SCBCD 1.3: 94%<br />SCWCD 1.4: 91%<br />SCJP 5: 95%
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: scjp1.4 qtn on Mult-dimensional array