SCJP 1.4 - 88%<br />SCWCD 1.5 - Preparing
SCJP 1.4 - 88%<br />SCWCD 1.5 - Preparing
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Originally posted by Manju Kavi:
if this is the correct coding, i agree with Ankith..
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
SCJP 1.4 - 88%<br />SCWCD 1.5 - Preparing
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Originally posted by vidhya suvarna:
Source: Whizlab SCJP1.4
public class Test{
public static void main(String args[]){
private int num;
public Test(int i){
num=i;
}
public int hashcode(){
int i=(int)(Math.random()*100);
return i*num;
}
}
}
a) code implements hashcode() correctly
b) code doesnot implements hashcode() correctly
c)This implementation is correct if and only if the equals() is not overridden
d) Given code doesnt contain enough information about correct implementation of hashcode()
e) None of these
According to me option b seems correct as for all objects created the hashcode() will return a unique value which is not as per the contract.
Kindly let me know if my answer is right or wrong? And if wrong please provide an explanation supporting your answer.
Originally posted by Manju Kavi:
I'm very sorry Ankit
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
SCJP 1.4 - 88%<br />SCWCD 1.5 - Preparing
Originally posted by Sampath Kumar:
"As per the contract of equals() and hashCode(), if we are overridding one we have to override the other". Is it a must condition?
SCJP 5.0, SCJD in progress
Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |