• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Arrays

 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

Please explain this code. How it works?


==========================================================



========================================================

Thanks in advance,
Mubeen Shaik.
 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi..
I also don't have any idea of how its working..
Help with answers please.
 
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Mubeen Shaik
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mike,

Thanks for the detailed explanation. But how the output is "A11".

Thanks in advance,
Mubeen Shaik
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mubeen, what's the type of the object that a3[2][1][0] refers to?
 
Mubeen Shaik
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Barry,

It refers to the type "class". Please correct me if i am wrong.

Thanks,
Mubeen Shaik
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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".
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 1272
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you use an object reference "r" where a String is needed, "r" is treated like "r.toString()", which returns a String.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic