Win a 3 month subscription to Marco Behler Videos this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

What is this fulfill Object.equals() contract?  RSS feed

 
O Shea
Ranch Hand
Posts: 65
1
Java MySQL Database Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



A) The output is true and MyStuff fulfills the Object.equals() contract.
B) The output is false and MyStuff fulfills the Object.equals() contract.
C) The output is true and MyStuff does NOT fulfill the Object.equals() contract.
D) The output is false and MyStuff does NOT fulfill the Object.equals() contract.

Answer is (C)-> I understand why but I didn't understand what is this fulfill the Object.equals()contract???

  Why answer is (C) and not (A)??
 
Piet Souris
Rancher
Posts: 1916
66
  • Likes 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The contract talks about things like:
always x.equals(x) if x != null
et cetera. Just google for it, or look into on of the OCA study guides.

An important part of the contract is:
if x and y are not null, then x.equals(y) if and only if y.equals(x).

Now, let m1 = MyStuff("tv") and m2 = MyStuff(null). Think about it.
 
O Shea
Ranch Hand
Posts: 65
1
Java MySQL Database Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok thanks
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!