File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A SCJP exam question (about array variable assign)

 
Shiao Kung Chux
Greenhorn
Posts: 25
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Max Habibi
town drunk
( and author)
Sheriff
Posts: 4118
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
bhavesh bhanushali
Ranch Hand
Posts: 55
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 25
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4118
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4118
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 25
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic