import java.util.*;
public class HashTest{
int hashCode;
public HashTest(int hashCode){
this.hashCode = hashCode;
}
public boolean equals(Object other){
if(other instanceof HashTest){
return ((HashTest)other).hashCode == this.hashCode;
}
return false;
}
public static void main(
String [] args) {
HashTest ob1 = new HashTest(3);
HashTest ob2 = new HashTest(2);
HashTest ob3 = new HashTest(1);
Map mp = new HashMap();
mp.put(ob1,"one");
mp.put(ob2,"two");
mp.put(ob3,"three");
ob1 = new HashTest(1);
System.out.println(mp.get(ob1));
}
}
a) one
b) two
c) three
d) null
e) Compilation fails
Why the answere is null?