When you call changeNumber()
, the reference to example
is copied and passed to the method. You change the value of number
, which modifies the referenced object, then reasssign a new instance to myClass
, which does not affect the original reference in main
.
Everything goes as expected, then you exit the method. Back to the main
method, you still have the primary reference to example
, which was affected by the first reassignment (of number
), but not by the reassignment of myClass
. That's why you have 99, not the original 28.