SCJP2
Originally posted by Tybon Wu:
String x = new String("abc");
String x1 = new String("abc");
The above code will create 2 String objects, since you explicitly use the new operator.
Originally posted by mou haj:
and while execution X and X1 will be created and both will be reffered ( or assigned) to the reference in the pool (ie to abc)
Originally posted by Fletcher Estes:
The above code actually creates 3 String objects. The first object is "abc" and this is put in the String pool. The second and third objects are referred to by x and x1, with contents, but not references, equal to "abc"
![]()
SCJP2
Here is where i think i am missing, what will happen to the string pool object since x , x1 have there own objects to which they refer and have their own contents.
if it were
String x = "abc";
String x1 = "abc";
Then no new objects is created and x , x1 will refer(point) to the object in the pool with contents "abc". Right?
Originally posted by Kitty Dayal:
Hi Fletcher,
What about this? How many are created(objects) and where?
String a = new String( "abc" );
String b = a;
String c;
c = a + b;
This is from Bill's book, in which he say's 2 objects. One with the 'a' and the other with 'c'. He does not say anything about the object created in the pool. Should we count the object created in the pool? Obviously c refers a different object.
Thanks,
Kits
SCJP2
You ought to ventilate your mind and let the cobwebs out of it. Use this cup to catch the tiny ads:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
|