Hi All,
My queries is,
Consider the following class:
public class X
{
private int a;
private int b;
public void setA(int i){ this.a = i; }
public int getA(){ return this.a; }
public void setB(int i){ this.b = i; }
public int getB(int b){ return b; }
public boolean equals(Object obj)
{
return ( obj instanceof X && this.a == ((X) obj).a );
}
public int hashCode()
{
//1
}
}
Which of the following options would be valid at //1?
a. return 0;
b. return a;
c. return a+b;
d. return a*a;
e. return a/2;
answer is a,b,d and e.
Is it because of the equals only evaluate on object a. Therefore, hashCode should not evaluate object b? I got confused. please help.
