This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can anybody give an example for this....

 
Manoj Mani
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
b.eqials(c) can return false even if c.equals(b) returns true.
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Manoj,

Don't you think, it violates the symmetric contract of the equals() method.



What is symmetric contract?
For any reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.




Regards,
cmbhatt
 
Manoj Mani
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ya thats right?But......

Given that b and c refer to instances of wrapper classes, which two statements are true? (Choose two)
A. b.equals(b) returns true.
B. b.equals(c) returns the same result as b == c.
C. b.eqials(c) can return false even if c.equals(b) returns true.
D. b.equals(c) throws an exception if b and c are different wrapper types.
E. b.equals(c) returns false if the type of wrapper objects being compared are different.

Answer: B, C

Thats why i asked......
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic