aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes q from Sreenivas Majji Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "q from Sreenivas Majji" Watch "q from Sreenivas Majji" New topic
Author

q from Sreenivas Majji

JayaSiji Gopal
Ranch Hand

Joined: Sep 27, 2004
Posts: 303
The following code will give

1: Byte b1 = new Byte("127");
2:
3: if(b1.toString() == b1.toString())
4: System.out.println("True");
5: else
6: System.out.println("False");

A) Compilation error, toString() is not avialable for Byte.
B) Prints "True".
C) Prints "False".

Why does this code return false? plz explain.


SCJP 1.4, SCWCD 1.4<br /> <br />Thanks in advance!<br />Jayashree.
sanjeevmehra mehra
Ranch Hand

Joined: Aug 21, 2004
Posts: 75
if(b1==b1) //true, comparing same object
if(b1.equals(b1)) //true, same String value returned by toString()


if(b1.toString()==b1.toString())//flase,
b1="hi";
b2="h1";
if(b1==b2)//false, comparing two different objects
if(b1.toString()(anonymous object one) == b1.toString()(anonymous object two))//flase, comparing two different objects.


thanks & regards,<br />Sanjeev.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: q from Sreenivas Majji