Oki, English is not my first language so I tend to look up English words a lot, just to make sure that I know what the word means. Immutable and mutable are words often used in OO programming, and I needed a good definition and examples as I was trying to explain this to a friend. Oki, the picture examples below are not perfect, but I couldn’t think of anything better. If you have a great example, please share! I’ll update the post and add new images 🙂
Immutable: The state of the object cannot be changed after creation
Example: String , you can’t change it after it is created. It looks like you can, but what happens is that a new string is created.
Mutable: The state of the object can be changed after creation
Example: Stringbuilder , you can change this object after you have created it. You can append, remove, replace, or insert characters to the same object,- a new one isn’t created as with String.