posted 16 years ago
Hi,
equals() is overriden in Wrapper classes and will return true iff
Compares this object to the specified object. The result is true if and only if the argument is not null and is an Integer object that contains the same int value as this object.
So if two instances of Integer/Wrapper classes are compared the result will be true iff both of them contain the same value.
Also if two instances of different wrapper classes are compared the result
will always be false.
So wrt above statement:
a) true
a.equals(a) will always be true
Which book or material has the above question you mentioned.
equals() is reflexive: for any non-null reference value x, x.equals(x) should return true.
b) false b==c will be true iff both b and c refer to same object
and b.equals(c) if both b & c are of same wrapper class type and contain same value
c)is false, because if c.equals(b) is true then b.equals(c) must be true.
It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true
d) b.equals(c) will return false if b and c reffer different Wrapper class types.
e)true.
So as per me the answer is a and e. I hope other ranchers agree to me.
I hope you to agree with me.
Could you please mention the book or material that had the questions.
Thanks
Deepak