• Post Reply Bookmark Topic Watch Topic
  • New Topic

Head First Java exercise question  RSS feed

 
Nikolas Nikolaou
Ranch Hand
Posts: 101
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi. There's an exercise In Head First Java pg 267 that I don't entirely understand the answer to.
According to the answer , there are 12 honeyPot references to the same Honey class object created In the code below.
The part I don't understand Is on line 17 an array of 4 honeyPot references Is created and on line 19 these references are assigned to another array.The answer shows that only the 4 references from the array on line 17(ha) are Included In the total.Shouldn't the array on line 19 (b1.beeHa) add another 4 references for a total of 16 ?

"In this code example,several new objects are created.Your challenge is to find the object that is 'most popular'
ie the one that has the most reference variables referring to it.Then list how many total references there are for
that object,and what they are."


 
Joanne Neal
Rancher
Posts: 3742
16
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nikolas Nikolaou wrote:on line 19 these references are assigned to another array

No they're not. There is only one array (the one created on line 17) and there are two references to this array (ha and b1.beeHA).
Arrays in Java are Objects and just as you can have multiple references to the one Honey object, you can have multiple references to the same array.
 
Nikolas Nikolaou
Ranch Hand
Posts: 101
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks! That clears things up
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!