• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

equals() method and == operator

 
Nesan Krish
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Head first EJB book page 292 question 6: According to basic Java rules if two objects are equals(), they are similar, identical but may not be the same. If two objects are == then they are same. Am I correct? Then the answer for this question should be A. Am I missing something? Please help! Thank you very much.
[ March 07, 2004: Message edited by: Nesan Krish ]
 
Janne Karhu
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If object1 == object2 returns true, they reference to the same object. But if object1 == object2 returns false, the objects may still refer to the same entity (i.e. the primary key objects contain the same data which implies that equals-method returns true).
Thus, only B is correct.
 
Nesan Krish
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does this mean that two seperate primary keys can point one entity?
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nesan,

Does this mean that two seperate primary keys can point one entity?

No. It means there are two objects holding same PK hence pointing to the same entity.
Regards
Maulin
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
also, can you post the question if its not big? I dont have the book.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic