What is the difference between a class and an object?
A class is a blueprint or template that defines what data and behaviour a type has. An object is a real instance of that class created in memory. The class is the design, and the object is the actual thing built from that design. One class can create many objects.
The blueprint idea
Think of a class like the architectural plan for a house. The plan lists the number of rooms and the layout, but you cannot live in a plan. An object is the real house built from that plan. From one plan you can build many houses, and from one class you can create many objects.
class Car { // class: the blueprint
String model;
void drive() { System.out.println("driving"); }
}
Car car1 = new Car(); // object 1
Car car2 = new Car(); // object 2
car1.model = "Tesla";
car2.model = "Honda";
Here Car is the class. The variables car1 and car2 are two separate objects. Each object has its own copy of the data, so changing car1 does not affect car2.
Quick comparison
- A class is a definition, an object is an instance of that definition.
- A class does not take memory for data on its own, an object takes memory when created.
- You write a class once, you can create many objects from it.
- The keyword new is used to create an object from a class in most languages.
Interviewers like a crisp one liner here. Say a class is a blueprint and an object is a real instance built from it, then give the house plan example. Mentioning that objects hold their own copy of the data shows you understand memory.
Common follow up questions
Related interview questions
Want the full OOP guide?
Read every OOP concept with notes, diagrams, and code in one place. Track your progress as you go.
Open the OOP guide All OOP questions