WalzoneInterview Prep
📞 Interviewing soon? Practice with a realistic AI mock phone interview — it calls you, then scores you. First 15 min FREE →

Software Engineering · Basic · question 11 of 100

What is the difference between a class and an object in object-oriented programming?

📕 Buy this interview preparation book: 100 Software Engineering questions & answers — PDF + EPUB for $5

In object-oriented programming, a class is a blueprint or a template for creating objects, while an object is an instance of a class.

A class describes a set of attributes and methods that define the behavior of the objects that belong to it. It specifies the properties that an object can have and the operations that can be performed on it.

For instance, consider a class named "Car". It could have properties such as "color", "model", "year", and "price". It could also have methods such as "drive", "stop" or "getPrice".

On the other hand, an object is an instance of a class. It is created from the class blueprint and represents a specific entity or thing. When you create an object of a class, it contains real values of the attributes defined by the class. You can access and manipulate the properties of the object and invoke its methods.

For instance, an object of the class "Car" can be created with specific values for each of its properties. E.g:

Car myCar = new Car();
myCar.color = "blue"
myCar.model = "Toyota"
myCar.year = 2020
myCar.price = 20000

With this object we could call methods or access its properties:

myCar.drive()
myCar.price

So, in short, a class is a template that defines what an object will be like, while an object is an instance of that class with specific values for its attributes.

Reading is step one. Saying it out loud is the interview. Our AI interviewer calls your phone and runs a realistic Software Engineering interview — then scores it.
📞 Practice Software Engineering — free 15 min
📕 Buy this interview preparation book: 100 Software Engineering questions & answers — PDF + EPUB for $5

All 100 Software Engineering questions · All topics