Hi, I have a doubt in this question. The following code will give: Byte b1 = new Byte("127"); if(b1.toString() == b1.toString()) System.out.println("True"); else System.out.println("False"); A. compilation error, toString() is not available for Byte. B. prints "True". C. prints "false". The given ans. is C. & it's correct. Can somebody explain me why? They are referring to the same object. Shouldn't it return true. Thanks, Kiran.
Joined: May 26, 2002
They are NOT refering to the same object. Note that the method Byte.toString() returns a NEW String object representing the byte value. Each time you use it, it creates a new String object.
Joined: Aug 13, 2000
Thanks Thomas. I somehow missed that point. Regards, Kiran.