| Author |
danchisholm.net exam3 Question 6
|
Dmitry Golynkin
Greenhorn
Joined: Aug 13, 2002
Posts: 23
|
|
Hi friends. It seems that must be an error because method variable d doesn't initialized, but the code compiles fine. WHY? [Code tags added by Val] [ August 19, 2002: Message edited by: Valentin Crettaz ]
|
good luck
|
 |
Valentin Crettaz
Gold Digger
Sheriff
Joined: Aug 26, 2001
Posts: 7610
|
|
Local variables are not required to be initialized as long as they are not used within the method's body. In this case, d is not used, and thus, the compiler doesn't need to complain. For more information, please read JLS 14.4 Local Variable Declaration Statements
|
SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
|
 |
Dmitry Golynkin
Greenhorn
Joined: Aug 13, 2002
Posts: 23
|
|
|
thank you Guru
|
 |
Dmitry Golynkin
Greenhorn
Joined: Aug 13, 2002
Posts: 23
|
|
code: __________________________________________________ Question 19 1. class Amber { 2. public static void main(String[] args) { 3. int[][] a = {{1,2},{'a'-'a','b'-'a','c''a'},{~0,2&3,1<<1}}; 4. Object[] obj = (Object[])a.clone(); 5. for(int i = 0;i<obj.length; i++) { 6. int[] ia = (int[])obj[i]; 7. System.out.print(ia[i]); 8. } 9. } 10. } __________________________________________________ What {1,2} and {~0,2&3,1<<1} are doing in the array initialization? ARE they array members? [ August 19, 2002: Message edited by: Dmitry Golynkin ] [ August 19, 2002: Message edited by: Dmitry Golynkin ]
|
 |
Valentin Crettaz
Gold Digger
Sheriff
Joined: Aug 26, 2001
Posts: 7610
|
|
First off, you should start another discussion when posting a new question unrelated to the one already under discussion. Let's rewrite this: As you can see, the array "a" is a bidimensional array containing integer primitives. The components of the array "a" are initialized by the expressions given in the array initializer (after the '=' sign). Thus, the array after initialization contains the following values: row 1: 1,2 row 2: 0,1,2 row 3: -1,2,2 Concerning the last subarray: ~0 inverts all bits of 0, which yields -1 2&3, that is, 00000010 & 00000011 yields 2 1 << 1 yields 2 And by the way (Dan?), I think there is a typo in the array initializer (unless the cut and paste didn't work). Second row, third component, 'c''a' should be something like 'c'-'a'. [ August 19, 2002: Message edited by: Valentin Crettaz ]
|
 |
Dan Chisholm
Ranch Hand
Joined: Jul 02, 2002
Posts: 1865
|
|
Originally posted by Valentin Crettaz: And by the way (Dan?), I think there is a typo in the array initializer (unless the cut and paste didn't work). [ August 19, 2002: Message edited by: Valentin Crettaz ]
It must have been a cut and paste problem, because the web page doesn't have the problem.
|
Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="http://www.danchisholm.net/" target="_blank" rel="nofollow">Try my mock exam.</a>
|
 |
Valentin Crettaz
Gold Digger
Sheriff
Joined: Aug 26, 2001
Posts: 7610
|
|
That's what I thought Dan Keep up the good work...
|
 |
 |
|
|
subject: danchisholm.net exam3 Question 6
|
|
|