
November 7th, 2012, 02:22 AM
|
 |
Contributing User
|
|
|
|
Hi,
This can be a tricky concept to understand when beginning Java.
Line 1 creates a new Shirt in memory and assigns myShirt as a reference to it.
Line 2 creates another Shirt in a different area of memory and assigns yourShirt as a reference to that.
Line 3 does not actually copy the properties. Instead, the myShirt reference is changed to point at the area in memory that yourShirt is pointing to. So now both myShirt and yourShirt references are pointing to the same thing.
Line 4 changes the color of the referenced Shirt.
Line 5 again changes the color of the same referenced Shirt.
Line 6 prints the color of the shirt through the myShirt reference. You would get the same result if you printed the color of yourShirt, as both references are pointing at the same thing.
Tutorial
Hope this helps
slink
Last edited by slink : November 7th, 2012 at 02:42 AM.
|