Codementor Events

Class vs Object vs Instance

Published Mar 13, 2020
Class vs Object vs Instance

Class

A Class defines the structure, property, and behaviour of an Object. You can think of a Class as a blueprint. Exactly like building a house, you use a blueprint to create a particular model, maybe a 3 bedroom detached dwelling. You would have a different blueprint for a 5 bedroom dwelling for example. Its the same with Classes in their simplest form, you could define a Class representing a 3 bedroom dwelling, and another Class that represents a 5 bedroom dwelling.

Object

An Object is created from a Class, like a house is created from a blueprint. You could use a blueprint of a 3 bedroom home to build multiple 3 bedroom homes - 1 blueprint to create multiple 3 bedroom homes. This is what happens with a Class. You can create multiple Objects from your single Class - remember, a Class is just the blueprint for creating Objects of the same type.

Instance

So we've taken our blueprint (Class), and created multiple 3 bedroom homes (Objects), but how do we refer to one particular home (Object) we've built? We refer to a particular Object as an Instance. If I were to paint the frontdoor of one of the homes, I would be painting the door of a particular Instance of the Objects (home) created from my Class (blueprint).

This is a very simplistic model but I hope it helps.

Discover and read more posts from Steve Donovan
get started
post commentsBe the first to share your opinion
Lakshita Kamboj
3 years ago

Thanks, Thanks, Thanks!!! I have started learning how to code very recently and was always confused about object, class, and instance. Your explanation has really helped me. Can’t thank you enough. Love from India.

Show more replies