File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

("String".toString() == "String")???

 
wei liu
Ranch Hand
Posts: 56
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Question 121)
Read this piece of code carefully
if("String".toString() == "String")
System.out.println("Equal");
else
System.out.println("Not Equal");
Answers

the code will compile an print "Equal".
the code will compile an print "Not Equal".
the code will cause a compiler error.
-----------------
the ans is the first one.why? Could anyone give me a clear idea?
esp.("String".toString() == "String")
 
wei liu
Ranch Hand
Posts: 56
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This object (which is already a string!) is itself returned.
i know the explanation!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic