• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Number of String objects

 
Apurva Gaonkar
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Campbell Ritchie
Sheriff
Pie
Posts: 49472
64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please don't post a new question on an existing thread. And we require you tell us where that question is from. Separating thread.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49472
64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Giovanni Lima
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic