posted 18 years ago
class A {
int i1, i2;
public void setI1(int i) {i1 = i;}
public int getI1() {return i1;}
public void setI2(int i) {i2 = i;}
public int getI2() {return i2;}
public A(int ii1, int ii2) {i1 = ii1; i2 = ii2;}
public boolean equals(Object obj) {
if (obj instanceof A) {
return (i1 == ((A)obj).getI1()) & (i2 == ((A)obj).getI2());
}
return false;
}
public int hashCode() {
// Insert statement here.
}}
If inserted at the specified location, which of the following statements would produce the most efficient hashCode method?
a. return 31;
b. return getI1();
c. return getI2();
d. return getI1() + getI2();
e. return 31 * getI1() + getI2();
f. None of the above
the answer is e, i think a is also correct because it is consistent.
can any body answer???