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.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Majji Mock Q #9  Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Majji Mock Q #9  " Watch "Majji Mock Q #9  " New topic
Author

Majji Mock Q #9

KN
Ranch Hand

Joined: Aug 13, 2000
Posts: 66
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
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
Thanks Thomas. I somehow missed that point.
Regards,
Kiran.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Majji Mock Q #9
 
Similar Threads
toString()
Q.9 from Majji's paper 1
Kumar #9
String Question
Why this prints false?