File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes A SCJP exam question (about array variable assign) 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 » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "A SCJP exam question (about array variable assign)" Watch "A SCJP exam question (about array variable assign)" New topic
Author

A SCJP exam question (about array variable assign)

Shiao Kung Chux
Greenhorn

Joined: Jan 26, 2006
Posts: 25
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 code can insert into line 7 and compile successful (choise 4)
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. b[0][1][0][0] = b[0][0];
F. b2[0][1] = big;

accord to the text book , the answer is A,B,E,F.

i do not understand why C is false? if C is false why E is true?
why D is false? if D is false, why A is true?


while everyone is busy , i am free
Max Habibi
town drunk
( and author)
Sheriff

Joined: Jun 27, 2002
Posts: 4118
Hi demilich,

Welcome to the ranch. We don't really have a lot of rules around here, and we really love to get new members, but I'm afraid that you're violating the few rules we do have.

We have a naming policy which states you need to have a name that I can't tell is fake. Right now, I can tell that your name is fake, so please change it to something that will confound me.

Also, please change your signature to something that doesn't include the word 'f*cking', or other, like-minded terms. While I'm personally a big fan, we get younger visitors here, and we like to keep the site work friendly.

Thanks,
Max


Java Regular Expressions
bhavesh bhanushali
Ranch Hand

Joined: Jun 13, 2005
Posts: 55
Hmm iam seeing the f word for the first time , I think some strict policies need to be placed with regards to using abuse
Shiao Kung Chux
Greenhorn

Joined: Jan 26, 2006
Posts: 25
Originally posted by Max Habibi:
Hi demilich,

Welcome to the ranch. We don't really have a lot of rules around here, and we really love to get new members, but I'm afraid that you're violating the few rules we do have.

We have a naming policy which states you need to have a name that I can't tell is fake. Right now, I can tell that your name is fake, so please change it to something that will confound me.

Also, please change your signature to something that doesn't include the word 'f*cking', or other, like-minded terms. While I'm personally a big fan, we get younger visitors here, and we like to keep the site work friendly.

Thanks,
Max
OK, i update
Max Habibi
town drunk
( and author)
Sheriff

Joined: Jun 27, 2002
Posts: 4118
Fair enough. If you'll please change your last name to something I don't recognize as obviously fake, I'll see about answering your question. Deal?

M
Max Habibi
town drunk
( and author)
Sheriff

Joined: Jun 27, 2002
Posts: 4118
Thanks!


QUESTION: why C is false?
ANSWER: b[0][0] is a int(namely, the number 5). However, b2[1][1][0] point to an array. You can't put an int into a space that's expecting an array, as b2[1][1][0] is.



QUESTION:if C is false why E is true?
ANSWER: because b[0][1][0][0] point to a position that holds a int. And b[0][0] is a int(namely, the number 5).


QUESTION: why D is false?
ANSWER: This is more subtle. b is a two dimensional array, but the position indicated by b2[1][2][0] can only hold a one dimensional array.

QUESTION:if D is false, why A is true?
ANSWER: b2 is a four dimensional array. At position b2[0][1], it can hold a two dimensional array. Since b happens to [b]be[/i] an two dimensional array, A is legal.

hth,
M
[ January 26, 2006: Message edited by: Max Habibi ]
Shiao Kung Chux
Greenhorn

Joined: Jan 26, 2006
Posts: 25
i see,

complex problem.

whatever, b2[][][] can put a one dimation array,
b2[][] can pub a two dimation array,
b2 [] can pub a tree dimation array,
 
Don't get me started about those stupid light bulbs.
 
subject: A SCJP exam question (about array variable assign)
 
Similar Threads
scjp1.4 qtn on Mult-dimensional array
Multidimensional Arrays
Doubt About the output of this Question
multi arrays
Self Test Question on Arrays by Kathy's Book