wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Question from Mock exam Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Question from Mock exam" Watch "Question from Mock exam" New topic
Author

Question from Mock exam

M Mehta
Ranch Hand

Joined: Aug 03, 2006
Posts: 92
Hi Ranchers,

I have a doubt on a question from the mock test of K&B book. The que is

Given
x=0;
if(x1.hashCode() != x2.hashCode()) x = x+1;
if(x3.equals(x4) == false)x=x+10;
if(x5.equals(x6)==true)x=x+100;
if(x7.hashCode()==x8.hashCode())x=x+1000;
System.out.print("x =" + x);

If the output is x=1111, whic of the following will always be true.

The answer given is x2.equals(x1)==true

I could nto undersatnd this question. According to me if the hash code of x1 and x2 are not equal then the values cannot be equal. Can you please help me on this?

Thanks,
Mehta
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9302
    
  17

yes you are right,if two objects are equal then they must produce the same hashCode

Check this in the question
Does the question says that the equals and hashCode methods are properly implemented or does the question gives the implementation of either one or both methods?


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
M Mehta
Ranch Hand

Joined: Aug 03, 2006
Posts: 92
This is the whole question. There is no other explanation given.
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9302
    
  17

what are the other options which are not correct....
Arijit Daripa
Ranch Hand

Joined: Aug 09, 2008
Posts: 142
May I have the Page No.


SCJP 5
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question from Mock exam