Topics Index


If you need explanation Read this topic

If you need Answer Take test on this topic

Which of the following is incorrect?

X: If o1.equals(o2), then o1.hashCode() == o2.hashCode() should always be true.
Y: If o1.hashCode() == o2.hashCode() is true, it doesn’t mean that o1.equals(o2) will be true.
A. X only
B. Y only
C. Both are correct
D. Both are incorrect
Topic: Collection Framework In Java

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

Ans is we have the hashCode() concept in general objects which are created dynamically dont have the name..objects are accessed using the address..the address is hold by the references..
case 1:
if the both objects content is same than we can not say their objects is also same some times it will true but not always..let us take 2 strings
String s1=new String("A");
String s2=new String("A");
if(s1.equals(s2)) is true but if(s1.hashCode()==s2.hashCode()) is not always true Bcz both are different objects..
some times it will be true like if both the strings are created in the SP
Case 2:
if bothe objects hashCode is same means both the references pointing the same content in the objects must be true..Bcz both the references pointing the same will be true

Posted by Uday Kumar    2015-02-12 16:57:51


Posted by Shubham Bansal    2015-02-13 03:14:39

This dose is now closed and the winners are Uday Kumar for the 'Popular Comment'. The 'lucky liker' is Shubham Bansal. Please login into Merit Campus using facebook, to claim your recharge. Go to to raise the recharge.

Posted by Merit Campus    2015-02-13 03:33:59

© meritcampus 2019

All Rights Reserved.

Open In App