Say I set int A = int B. When I change A after, it will not change the value of B. But when I set a SomeClass A = SomeClass B, and I change A\'s contents (like a.cost), it c
Yes, it does - but the value of A is a reference, not a copy of the object itself.
I like to give the following analogy...
Suppose two people both have my address: that's like two variables of type House in Java. Now one of them comes and paints my door red. The second person will still see the red door if they visit:
House jonsHouse = new House(); // Even the variable jonsHouse is only a reference
House firstAddressCopy = jonsHouse; // Just a copy of the reference
House secondAddressCopy = jonsHouse; // Just a copy of the reference
firstAddressCopy.paintDoor(Color.Red);
Color color = secondAddressCopy.getDoorColor(); // Now color will be red
Basically, remember a few rules and things will become clear: