Q 3. Which two statements are true about comparing two instances of the same class, given that the
equals() and hashCode() methods have been properly overridden? (Choose two.)
A. If the equals() method returns true, the hashCode() comparison == must
return true.
B. If the equals() method returns false, the hashCode() comparison != must return
true.
C. If the hashCode() comparison == returns true, the equals() method must return
true.
D. If the hashCode() comparison == returns true, the equals() method might
return true.
E. If the hashCode() comparison != returns true, the equals() method might
return true.
As per table 418 of k&b book, options B and D are correct.But the book says only option b is correct
the explanation why D is not correct is nonsense
Q 10.Given the following,
1. public class X {
2. public static void main(
String [] args) {
3. X x = new X();
4. X x2 = m1(x);
5. X x4 = new X();
6. x2 = x4;
7. doComplexStuff();
8. }
9. static X m1(X mx) {
10. mx = new X();
11. return mx;
12. }
13. }
After line 6 runs. how many objects are eligible for garbage collection?
A. 0
B. 1
C. 2
D. 3
E. 4
when i had solved this question previously i was quite convinced that the answer is B.
But as i solved it again today, i got confused and marked answer A. could anyone please
conveince me how come the answer is A.