Before discussing the difference between mutable
and immutable
objects, it's important that we properly define what an Object
is in Object-Oriented Programming (OOP). This will serve as one of the foundations/basic concepts to fully understand the topic.
So to start, an Object
is a piece of data that contains its own:
- identity (unique name),
- states (characteristics or attributes) and,
- behaviors (methods).

For example, assume that we are going to adopt a dog (or a cat!). After adoption, we would give that dog a name to call it (to uniquely identify it-- especially when we take it outside for a walk). Our dog has different attributes, including but not limited to, breed
, color
, and age
. Finally, the dog may perform several functions like eating, sleeping, and barking.
Let’s have a look at another example of an object:

The above figure illustrates a house having a unique house number plate. It also has certain features like roofColor
and doorColor
, along with certain functions like the doorOpens
and doorShuts
.
To extend our understanding, it's also crucial that we understand that an object is a specific "realization" of a class
. You can describe a class
as a logical entity which is responsible for creating individual objects. You may create multiple objects from a single class-- but it's imperative that a class always comes first whenever an object has to be created. It is a blueprint of sorts. Therefore, an object can also be defined as an instance of a class.
Keeping the above discussion in mind, let’s dive into the details of mutable and immutable objects.