Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

How many objects are created when we create String class
object using new operator?

Answer Posted / eknath wagadre

No!!!!!!!!!!!!!!!!!!!!

According to the Question it will creating only One object
in the Heap only..........

if we are using String str = new String("abc"); for this
statement only one object is creating in the heap only....

if we are using the code like

String str = "abc";
String str = new String("abc");

In this case only one object is creating in the heap.bcz of
in first line obviously one object is creating in the pool
and assigning the reference(S) to abc. now come in second
line it's creating object in heap but jvm will checking for
reference(s) bcz both object reference is same so now (s) is
pointing to abc which is in heap and pool object is
collected by GC. now we have only one object is heap.


if we are using the code like

String str ="abc";
String str1 = "abc";
String str2 =new String("abc");

Then only two object is creating one in string content pool
and another one is in heap.

Thank's
Eknath

Is This Answer Correct ?    16 Yes 6 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can you declare an interface method static?

1063


What is the difference between the size and capacity of a vector?

1044


What is callablestatement? How you can call stored procedure to pass in parameter?

1025


What are user defined exceptions?

1051


Explain an intermediate language?

971


How many threads can I run java?

1117


explain the difference between jdk and jvm?

999


What is difference between this and super keyword?

988


Is char a method in java?

1067


What is the difference between the Reader/Writer class hierarchy and the InputStream/OutputStream class hierarchy?

1132


Explain features of interfaces in java?

991


What is the difference between length and length() method in java?

1120


When is the finalize() called? What is the purpose of finalization?

1080


Why is multiple inheritance not supported in java?

1033


What is string in java with example?

1024