GeeCON Prague 2014*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Creating String Objects Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Creating String Objects" Watch "Creating String Objects" New topic
Author

Creating String Objects

Sumi Festus
Greenhorn

Joined: Feb 04, 2005
Posts: 14
Hi..
this was a question i stumbled upon
String x=new String("xyz");
String y="abc";
String x=x+y;

The answer says that 4 String objects are created can someone give me an explanation as to how 2 string objects are being created in the first line...
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608
A String instance is created that represents the String literal, which is passed to the String(String) constructor to create yet another String instance.


Tony Morris
Java Q&A (FAQ, Trivia)
 
GeeCON Prague 2014
 
subject: Creating String Objects