• 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:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

matching reference variables with objects

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm having trouble underdstanding this code. The book wants me to match the reference variable with the object variable. can some one explain this to me.




In the book
hq[4] match id = 0
hq[3] matches id = 2
hq[1] matches 1d =1
 
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

alex lesta wrote:I'm having trouble underdstanding this code. The book wants me to match the reference variable with the object variable. can some one explain this to me.


What an utterly boring and pointless lesson. My first suggestion is to get another book. Surely there is one that doesn't subject you to this kind of nonsense. I can write exercises better than this.






In the book
hq[4] match id = 0
hq[3] matches id = 2
hq[1] matches 1d =1



So the last time anything was assigned to the element at 4 was when it was assigned the element at 0, which had not been replaced since the loop. So hq[4] now refers to an element with an id of 0.

The last time hq[3] was assigned, it was for the element at 2, which had not been reassigned since the loop, so hq[3] now refers to an object with an id of 2.

hq[1] was not reassigned since the loop, so it still refers to an object with an id of 1.

I hope that helps.

rc
 
alex lesta
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ralph Cook wrote:Thank I think i got it. I am reading head java first. can you give any referals on any other book.

alex lesta wrote:I'm having trouble underdstanding this code. The book wants me to match the reference variable with the object variable. can some one explain this to me.


What an utterly boring and pointless lesson. My first suggestion is to get another book. Surely there is one that doesn't subject you to this kind of nonsense. I can write exercises better than this.






In the book
hq[4] match id = 0
hq[3] matches id = 2
hq[1] matches 1d =1



So the last time anything was assigned to the element at 4 was when it was assigned the element at 0, which had not been replaced since the loop. So hq[4] now refers to an element with an id of 0.

The last time hq[3] was assigned, it was for the element at 2, which had not been reassigned since the loop, so hq[3] now refers to an object with an id of 2.

hq[1] was not reassigned since the loop, so it still refers to an object with an id of 1.

I hope that helps.

rc

 
Ralph Cook
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you put your response within the quote tags, it makes it look like I said it.

No, I don't have another book, just a conviction that there must be a better one somewhere.

rc
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic