I think the confusion is with what the variable "name" represents. The reference variable *name* does not contain the string value "Sang" or "Shin" inside it. *name* is a reference variable of type string that can reference (point to) a String object in memory. A reference variable of type String can reference (point to) any String object in memory. The actual String object can not be changed (hence, immutable) and once it's dereferenced, will be up for garbage collection. The example below does this with the String object "Sang".

On 8/30/2011 2:07 PM, VM wrote:
Why is String considered immutable while the code below works?

String name = "Sang"; System.out.println(name);
name ="Shin";
System.out.println(name);


--
To post to this group, send email to javaprogrammingwithpassion@googlegroups.com
To unsubscribe from this group, send email to 
javaprogrammingwithpassion+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/javaprogrammingwithpassion?hl=en

Reply via email to