Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regarding with object equality

 
Mushfiq Mammadov
Ranch Hand
Posts: 187
25
Java jQuery Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Consider: o1 and o2 denote two object references to two different objects of the same class. Which of the following statements are true?
You had to select two options

a. o1.equals(o2) will always be false.
b. o1.hashCode() == o2.hashCode() will always be false.
c. o1 == o2 will always be false.
d. Nothing can be said about o1.equals(o2) regarding what it will return based on the given information.
e. Nothing can be said about o1 == o2.

Your answers and explanations are interesting and important. Thanks in advance
 
Mushfiq Mammadov
Ranch Hand
Posts: 187
25
Java jQuery Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note: This post did not quite meet our publishing standards and is hidden from view. Please check your PMs for why and edit this post to fix it. A moderator will review your change and consider publishing it.

It's a pity that I don't know source. This question was asked us by someone and our answers were different - [d,e], [c,d], [a,b,c], .. It is a disputable question for us. Now we would like to know the correct answers so I share it. But I am obliged to delete it if it didn't meet publishing standards
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mushfiq Mammadov wrote:It's a pity that I don't know source.

Paul Anilprem confirmed it is a question from Enthuware. This is really a great question. Loving it! Kudos to Enthuware for creating such a nice question For me such questions really prove the quality of Enthuware's mock exams!
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mushfiq Mammadov wrote:Your answers and explanations are interesting and important. Thanks in advance

I would select C and D as the correct answers. As the OCAJP forum leader, I'm taking a big risk here

Why?
1/ The questions clearly states two different objects of the same class. So that means you can use the == operator to compare two reference variables and because both objects are different (and thus not refering to the same object), o1 == o2 will always be false. That's why C is correct.
2/ Because nothing is said about the equals method, it's impossible for me to know if the equals() method of Object is overridden in this class or not. Hence it's impossible to know what the equals() method will return. So D is a correct answer as well.

Hope it helps!
Kind regards,
Roel
 
Paul Anilprem
Enthuware Software Support
Ranch Hand
Posts: 3819
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roel De Nijs wrote:
Mushfiq Mammadov wrote:Your answers and explanations are interesting and important. Thanks in advance

I would select C and D as the correct answers. As the OCAJP forum leader, I'm taking a big risk here

And you would be correct! Not that you need any confirmation


Why?
1/ The questions clearly states two different objects of the same class. So that means you can use the == operator to compare two reference variables and because both objects are different (and thus not refering to the same object), o1 == o2 will always be false. That's why C is correct.
2/ Because nothing is said about the equals method, it's impossible for me to know if the equals() method of Object is overridden in this class or not. Hence it's impossible to know what the equals() method will return. So D is a correct answer as well.

The explanation given with the question also says the same thing.
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Anilprem wrote:And you would be correct!

Phew, what a relief!
 
Mushfiq Mammadov
Ranch Hand
Posts: 187
25
Java jQuery Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roel De Nijs wrote:Paul Anilprem confirmed it is a question from Enthuware.


I know such this thread was already removed from forum. I was surprised when I saw this question again

Thanks, Paul for determining the source of this question

Thanks, Roel for your answer and explanation
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic