• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Mock Question HFEJB page 426. Q4.

 
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic