What is the difference between an Object and a Class?
Last updated
A class is the blueprint or template that defines properties and methods, while an object is a concrete instance of that class created in memory with its own data.
Class: A definition written once with
class; describes structure and behavior but holds no live data by itself.Object:
A runtime instance created with
new; each has its own property values and a unique identity.Many objects can be instantiated from one class, each independent.
Analogy: the class is the cookie cutter, the objects are the individual cookies.
[lang:php]
class Car { public string $color; }
$a = new Car(); $a->color = 'red';
$b = new Car(); $b->color = 'blue';
// Car is the class; $a and $b are distinct objects