When working with Object-Oriented Programming (OOP), there are three words you will use constantly: OBJECTS, CLASS, and INSTANCE.
Don’t worry, you’ll get used to them almost effortlessly and use them constantly. But, logically, we have to explain them (because besides programming well, it’s also important to speak well).
Let’s start with OBJECTS. As we already know, they are the basis of Object-Oriented Programming. We have already explained what objects are in this article.
As a quick reminder, an OBJECT is a way to model a part of reality. The object contains,
- State, through fields
- Behavior, through methods
And furthermore, for it to be a “real” object, it must be treated by your program with certain considerations or particular “rules”.
With this refreshed, let’s now explain the concepts of class and instance.
Class
A CLASS is the formal definition of our Object. We can think of it as a “mold” or template for creating objects.
In the Class, we define the properties and methods that objects created from the class will have.

We’ll make it easier with a simple example. Suppose you want to make a program that works with people (for example, to keep a list of students in a classroom, for them to buy things, for whatever you want).
The Persona class contains the definition of “what a Person has”. Let’s assume that in your program, a person is simply “something” that has:
nombre, which is textedad, which is an integer.
Furthermore, your Persona can introduce themselves (how nice of them). For which it has a method that prints a message on the screen using the values of the nombre and edad fields.
Let’s see how this would be done in different programming languages,
public class Person {
// Fields or properties
public string name;
public int age;
// Method
public void Introduce() {
Console.WriteLine($"Hello, my name is {name} and I am {age} years old.");
}
}
class Person {
public:
// Fields or properties
string name;
int age;
// Method
void introduce() {
cout << "Hello, my name is " << name << " and I am " << age << " years old." << endl;
}
};
class Person {
// Fields or properties
constructor() {
this.name = "";
this.age = 0;
}
// Method
introduce() {
console.log(`Hello, my name is ${this.name} and I am ${this.age} years old.`);
}
}
class Person:
# Fields or properties
def __init__(self):
self.name = ""
self.age = 0
# Method
def introduce(self):
print(f"Hello, my name is {self.name} and I am {self.age} years old.")
Instance
Once we have defined a CLASS, we can start creating objects from the “mold” it defines.
An instance is each of the elements created according to a class.
Each INSTANCE is an independent element, which has its own values for the properties defined in the class.
Furthermore, of course, you can have multiple instances created from a class (in fact, it’s normal to have several instances of a class).
Now let’s see it with some examples in the main programming languages. In the following codes, we create two instances of the Persona class:
- One for Luis, aged 30
- Another for Maria, aged 20.
Additionally, we call the Presentarse method of each instance so they print a friendly introduction message in the console (with their respective names and ages).
// Create an instance of the Person class
Person personLuis = new Person();
personLuis.name = "Luis";
personLuis.age = 30;
// Call the Introduce method
personLuis.Introduce();
// Create another instance of the Person class
Person personMaria = new Person();
personMaria.name = "Maria";
personMaria.age = 20;
// Call the Introduce method
personMaria.Introduce();
// Create an instance of the Person class
Person personLuis;
personLuis.name = "Luis";
personLuis.age = 30;
// Call the Introduce method
personLuis.introduce();
// Create another instance of the Person class
Person personMaria;
personMaria.name = "Maria";
personMaria.age = 20;
// Call the Introduce method
personMaria.introduce();
// Create an instance of the Person class
const personLuis = new Person();
personLuis.name = "Luis";
personLuis.age = 30;
// Call the Introduce method
personLuis.introduce();
// Create another instance of the Person class
const personMaria = new Person();
personMaria.name = "Maria";
personMaria.age = 20;
// Call the Introduce method
personMaria.introduce();
# Create an instance of the Person class
personLuis = Person()
personLuis.name = "Luis"
personLuis.age = 30
# Call the Introduce method
personLuis.introduce()
# Create another instance of the Person class
personMaria = Person()
personMaria.name = "Maria"
personMaria.age = 20
# Call the Introduce method
personMaria.introduce()
As we see, each of the instances is independent of the others and has its own data. In the example, each Persona has its own nombre and its own edad.
Furthermore, when they call the Presentarse method, they access their own values. Each instance is, wrapped up and independent, with its own data.
Best Practices tips
Now some general comments and thoughts.
There is no single correct way
First, let’s be clear that there is no single way to model a person. For you, it might have nombre and edad. But for someone else, it might have nombre, fecha nacimiento, and dni.
Some ways will give you fewer problems than others at some point. For example, edad is probably not a good idea because it changes every year. Fecha nacimiento will likely give you fewer problems in the future.
But even so, there is no single correct way. What you include or don’t include will depend on your needs and those of your project. And a bit of “extra cleverness” about what might cause problems at some point.
The word “object”
Another special bonus for talking about the word “Object”. In principle, the concepts OBJECT, CLASS, and INSTANCE are related but different concepts.
On one hand, CLASS and INSTANCE represent very different things. There is no doubt about their usage here. The class is the “mold,” and the instance is “what you create” with that mold.
But regarding the word “Object”… well. When you’re in day-to-day conversations with other programmers, you’ll end up using it to refer to both class and instance.
For example, sometimes you’ll say “we need to create a student object.” And here you’re actually referring to creating an Alumno class. But other times you’ll say “this object here is giving me a problem,” and there you’re probably referring to an instance.
In the end, don’t obsess over it, words are words. The important thing is to understand the concepts well and to understand each other when you talk to someone.
