I can't wrap my head around the idea that myObject is not changed to 5 and still remains with the value of 2? In other words, I think that this should output "5 5", but instead it outputs "2 5".
The way that I understand this, myObject is a reference variable. It points to an object on the heap that has an instance variable with the value of 2 at the beginning of the program. What really happens in the MyHeadHurts method when myPrimitive is assigned to myObject? It changes the value in the object's instance variable from 2 to 5. Why is this not reflected in the value of myObject's instance variable in the main method?
In other words, I realize that in the MyHeadHurts method I have a copy of the address to the object, but isn't it still pointing at the same instance variable on the heap? I hope I have explained this clearly.