Hi.. I also don't have any idea of how its working.. Help with answers please.
SCJP 1.4<br />" Something is difficult doesn't mean you shouldn't try, it only means you should try harder "
Mike Gershman
Ranch Hand
Joined: Mar 13, 2004
Posts: 1272
posted
0
a1 refers to a 1 dimensional array, type A11[], of one component containing a reference of type A11 to the one and only instance of a class A11 object.
a2 is a 2 dimensional array, type A11[][], with two rows. Each row is that same one dimensional array referred to by a1.
a3 is a 3 dimensional array, type A11[][][], with 3 slices. Each slice is that same 2 dimensional array referred to by a2.
so a3's maximum subscripts are a3[2][1][0]
a2 actually refers to a 1 dimensional array of 2 references of type A11[]. Both references are set to the same value by copying the value of a1.
a3 actually refers to a 1 dimensional array of 3 references of type A11[][]. All 3 references are set to the same value by copying the value of a2.
The output is "A11".
[ December 15, 2004: Message edited by: Mike Gershman ] [ December 15, 2004: Message edited by: Mike Gershman ]
Mike Gershman
SCJP 1.4, SCWCD in process
Mubeen Shaik
Ranch Hand
Joined: Jan 26, 2004
Posts: 67
posted
0
Mike,
Thanks for the detailed explanation. But how the output is "A11".
Thanks in advance, Mubeen Shaik
Barry Gaunt
Ranch Hand
Joined: Aug 03, 2002
Posts: 7729
posted
0
Mubeen, what's the type of the object that a3[2][1][0] refers to?
It refers to the type "class". Please correct me if i am wrong.
Thanks, Mubeen Shaik
Barry Gaunt
Ranch Hand
Joined: Aug 03, 2002
Posts: 7729
posted
0
I was expecting you to answer "a3[2][1][0] refers to an object of type (or class) A11". So when you try to print such an object the class' toString() method would be called. And what does the toString() method do for class A11? It returns the string "A11".
Jugal Hans
Greenhorn
Joined: Aug 30, 2004
Posts: 17
posted
0
so when you try to print such an object the class' toString() method would be called.
why would the method be implicitly called ?
Mike Gershman
Ranch Hand
Joined: Mar 13, 2004
Posts: 1272
posted
0
When you use an object reference "r" where a String is needed, "r" is treated like "r.toString()", which returns a String.