Win a copy of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications this week in the Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

QNo. 4 Ch-6 Coffee Cram Mock Exam!!  RSS feed

 
Puneet Vashisht
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Given the container-managed unidirectional relationship:

Foo(0-1) --> Bar(0-1)

And the object relations:

f1->b1
f2->b2

What will be true after the following code runs?

f2.setBar(f1.getBar());

A. f1.getBar() == null
B. b2.getFoo() == null
C. b1.getBar() == null
D. None of the above.

Correct Ans : (A,B) according to the book.

My question is if it is a unidirectional relationship how can b2 call getFoo() method. Meaning in a unidirectional relationship only one entity can references of other. That means if Foo has a getBar() method, then Bar cannot have a getFoo() method, if it has to be a unidirectional relationship. This can be verified at HFEJB PGNo. 391, where a unidirectional relationship is defined between Movie and Trailer. And only Movie cant get the Trailer references through getTrailer.

Please help me on this.

Thankz,
Puneet
 
Greg Charles
Sheriff
Posts: 3015
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's actually chapter 7, question 4. You may have a error in your printing that's been fixed in mine. Mine shows that A is the only correct answer.
 
Puneet Vashisht
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thankz greg,

i'm assuming that it is an printing error then, because the option cant be correct anywayz..

thankz
puneet
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!