Hi all,
I have been told that variables containing objects are basically just references to a memory locations that contain the object data. And doing something like this:
TestObject o1 = new TestObject(..);
TestObject o2 = o1;
would make a new variable o2 that will simply point to the same memory location as o1.
To test this, i used to following code:
public static void main(String[] args) {
String s1 = "82938";
String s2 = s1;
System.out.println(s1);
s2 = "changed";
System.out.println(s1);
}
If Objects really worked that way, then this code would have meant the following:
1)Reserve a memory location, store "82938" in it, and let the name s1 point to it
2)Let the name s2 also point to that same memory location
3)print whatever s1 points to
4)change what s2 points to to "changed"
5)print whatever s1 points to
since s1 and s2 point to the same thing, one would expect the last line to print "Changed".
However, i got the following output:
82938
82938
Can someone please tell me what knowlege am i missing?