I'd like to know what happens behind the scenes with this call in main and this settor. So in main a have some object of class Vehicle and i want to set its name i also have some strings.
Now here's my doubt. When i do ; honda gets the name civic. if i then in main do s1 = s2, s1 now points to "concerto" but the honda object still prints civic. I thought when i did setName the variable was pointing to s1 but it seems that instead it does a copy?
s1 holds a reference to the string "civic". When you call setName passing in String s1 you pass the value of the reference which you then assign to 'name'. 'name' now holds a reference to "civic", its not pointing to s1 and it's not holding a copy of "civic" so when you assign s2 to s1 'name' is not affected at all.
That was just to show my doubts. Now i know that after calling a settor with a string in main function changing that string later won't change the object because the field in the object still points to the string used in the settor. There was some confusion in my head but now it's all clear, thanks for help.
Chris, from your example and your comments there still might be confusion. What you are asking about is basic life, scope, and visibility. It is not that easy of concept to illustrate, but there is a small code example that I hope will do the job for you:
Out on HF and heard nobody, but didn't call CQ? Nobody heard you either. 73 de N7GH
All that thinking. Doesn't it hurt? What do you think about this tiny ad?