my dog learned polymorphism
The moose likes Beginning Java and the fly likes Number of String objects Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Number of String objects" Watch "Number of String objects" New topic
Author

Number of String objects

Apurva Gaonkar
Greenhorn

Joined: Feb 07, 2011
Posts: 4
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

Joined: Oct 13, 2005
Posts: 32668
    
    4
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

Joined: Oct 13, 2005
Posts: 32668
    
    4
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

Joined: Aug 05, 2005
Posts: 3011
    
    9
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.


Joanne
Giovanni Lima
Greenhorn

Joined: Mar 08, 2011
Posts: 13
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,


 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Number of String objects
 
Similar Threads
Strings
number of objects created?
String Object query
String Doubt
String Objects