This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
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 ]
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 ]