Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General 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:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Mock Question HFEJB page 426. Q4.

 
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello fellow ranchers,

The result of the f2.setBar(f1.getBar()); operation is that f1 has a broken link, b2 has a broken link and f2 is linked to b1. The linkages are UNIdirectional, meaning that Foo can access Bar but Bar cannot access Foo. This suggests to me that the operation b2.getFoo() should fail since Bar does not have a link to Foo (see page 391). Similarly b1.getFoo() should fail, even though, in this case, there is a link but it goes in the wrong direction. So I would say A is correct. In the book, it says B is also correct. Can anyone see why?

regards and thanks,
Simon
 
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe that the book is wrong, only A is correct.
 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can we think of it in this way -
after the code runs
step 1. f1.getBar() returns b1 and f1's link to b1 is broken.
step 2. f2.setBar(f1.getBar()) links f2 with b1. Now, b2 loses
its link to f2.

So, since f1 and b2 both get disconnected with their partners,
f1.getBar() = null and
b2.getFoo() = null but
b1.getFoo() = f2.

This is my understanding. Correct me if I am wrong.

Regards
Suman
 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Suman
I agree with Roger. The point is the relationship is Unidirectional. Bar does not have knowledge of foo. It can't access foo


The books errata does not state anything. Can Kathy or someone explain it how if the answer is both A & B

Thanks
 
Getting married means "We're in love, so let's tell the police!" - and invite this tiny ad to the wedding:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic