Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Ranch Hand
Posts: 207
3
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)??
 
Master Rancher
Posts: 2643
91
  • 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: 207
3
Java MySQL Database Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok thanks
 
I AM MIGHTY! Especially when I hold this tiny ad:
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!