This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

matching reference variables with objects

 
alex lesta
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • 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
 
Ralph Cook
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
  • 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
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic