A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Programmer Certification (SCJP/OCPJP)
a question about string
Joined: Feb 15, 2004
May 19, 2004 19:09:00
Please look at the following code,
x= new String("abc");
how objects are created?
Joined: May 09, 2004
May 19, 2004 20:10:00
Hope your question is not complete.
if your question is "how objects are created?" then the answer is when you use new keyword an instance to the String class is created in the heap.
if your question is "how many objects are created? " then the answer is 1
Anuradha<br />(SCJP 1.4)
Joined: Aug 03, 2002
May 19, 2004 23:04:00
Anu check this out:
new String("abc") == "abc"
returns false. So a new object is created which is different to the object "abc" residing in the string pool. So if this is the first time "abc" is used, then you could say
objects are created.
Ask a Meaningful Question
Getting someone to think and try something out is much more useful than just telling them the answer.
I agree. Here's the link:
subject: a question about string
How many String objects have been created?
doubt in string question in Kathy Sierras SCJP book
String garbage collection understanding
How many string objects ?
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2015