This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
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.
thomas
Ranch Hand
Joined: May 26, 2002
Posts: 79
posted
0
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.
KN
Ranch Hand
Joined: Aug 13, 2000
Posts: 66
posted
0
Thanks Thomas. I somehow missed that point. Regards, Kiran.