Forums Register Login

Number of String objects

+Pie Number of slices to send: Send
hey ,

Thats wonderful clearing the concepts of references & values .
I just want to make things more clear here .

String a="Hello";
String b="HI";

String x=new String("ABC");
String y=new String("XYZ");

Can anyone please tell how many reference and how many object are there in four different expressions?

My Answer would be 4 reference variable and 2 Objects.
a,b,x,y are reference variables of Type String

And There are 2 Objects of Type String . As we have new String("ABC") and new String("XYZ");
here does these Objects have names ? or can we name them ?

-regards
Apurva
+Pie Number of slices to send: Send
Please don't post a new question on an existing thread. And we require you tell us where that question is from. Separating thread.
+Pie Number of slices to send: Send
I separated those posts because they were unrelated to the original thread.

Please search the fora; there are many questions asked similar to this one.
+Pie Number of slices to send: Send
 

Apurva Gaonkar wrote:And There are 2 Objects of Type String


Actually there are 6.
As Campbell said, search the fora for similar questions if you're not sure why.
+Pie Number of slices to send: Send
In fact, you'd created 4 strings into the pool and two objects in the heap, which refer to two strings in the pool.

You can see the difference if try make any compare:



but,


Without deviation from the norm, progress is not possible - Zappa. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1252 times.
Similar Threads
String Objects
String Doubt
String Object query
Strings
number of objects created?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 15:33:39.