my doubt is here when i calling method(String s) by passing static String its print New InstanceAdd its ok ... after i am tring to print static variable s , its print newInstance why its print like this instant of New InstanceAdd ??? here what the mean of static ???
Thanks in advance kumaresan [ July 28, 2006: Message edited by: kumaresan natarajan ]
Thanks and Regards
kumaresan N
Andy Morris
Ranch Hand
Joined: May 30, 2004
Posts: 78
posted
0
Strings are immutable, meaning you can cannot change the value of them.
When you call 'method()', you pass it a COPY of the static reference (still refering to the same String object). However, you then re-assign the value that it refers to. i.e. s+="Add";
The original static reference still refers to the 'newInstance' String, and the copy of the original reference now refers to the newly created 'newInstanceAdd' String.
One more thing, this example does try to confuse you by 'shadowing' reference variables (giving the same name to multiple references - their scope determines which one you access unless you use keywords like 'this' or use the class name.
[ July 28, 2006: Message edited by: Andy Morris ] [ July 28, 2006: Message edited by: Andy Morris ]
Gowher Naik
Ranch Hand
Joined: Feb 07, 2005
Posts: 643
posted
0
Ok how many objects are created in above piece of code According to me there are 5 objects created as follows
Barry Gaunt
Ranch Hand
Joined: Aug 03, 2002
Posts: 7729
posted
0
You are hijacking, this topic. If you want to change the question, then please start a new thread. [ July 28, 2006: Message edited by: Barry Gaunt ]