In your example, the variable a
is just a reference to an instance of a string object. When you say a = "ty"
, you are not actually changing the string object, but rather pointing the reference at an entirely different instance of the string class.