Win a copy of Pragmatic AI this week in the Artificial Intelligence forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

matching reference variables with objects  RSS feed

 
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
 
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!