posted 10 years ago
Hi,
Is this erroneous?
Given:
And these two fragments:
I. public int hashCode() { return size/5; }
II. // no hashCode method declared
If fragment I or II is inserted, independently, at line 8, which are true? (Choose all that apply.)
A. If fragment I is inserted, the output is 2
B. If fragment I is inserted, the output is 3
C. If fragment II is inserted, the output is 2
D. If fragment II is inserted, the output is 3
E. If fragment I is inserted, compilation fails
F. If fragment II is inserted, compilation fails
My problem is that what happens if the two Turtle(1) objects end up in the same bucket? That would be hypothetically possible. Right?
(Because you cannot uniquely map 2^32 numbers to the number of buckets (as there are usually less number of buckets than 2^32).
What would happen then ? So for code fragment II. the result depends on the actual memory location of the two Turtle(1) objects (on
which the hash code values depend).
Cheers
Jozsef