In object oriented programming, a class is a construct that defines a collection of properties and methods. You can think of it as a template. For example, the following PHP code declares a class named "Item" and instantiates two objects of that class — a book and a vinyl record:

class Item {
  public $itemType; /* e.g. this could be "Book" or "CD" */
  public $price;
  public function printPrice() { 
    echo "The price of this {$this->itemType} is {$this->price} dollars."; 
  }
}

$catch22 = new Item();
$catch22->itemType = "Book";
$catch22->price = 25;
$catch22->printPrice(); /* prints: The price of this Book is 25 dollars. */

$americanPrayer = new Item();
$americanPrayer->itemType = "Vinyl Record";
$americanPrayer->price = 22;
$americanPrayer->printPrice(); /* prints: The price of this Vinyl Record is 22 dollars */

Note that in this example, $catch22 and $americanPrayer are 2 objects. Objects are instances of a class. They share the common structure that the class defines. This common structure consists of the properties ($itemType and $price in the above example) and methods (functions; printPrice() in the above example) of the class. However, the properties of different objects may be different.

In the above example, the price and item type are different for 2 objects of the same class. But both objects have a printPrice() method, a price property and an itemType property that can be used.

Comparison chart

Class versus Object comparison chart
Edit this comparison chartClassObject
Definition Class is mechanism of binding data members and associated methods in a single unit. It is a blueprint for creating objects. An object is an instance of a class. Typically, it is assigned to a variable.
Nature A class is abstract. An object is concrete. It can contain data and can represent an entity.
Memory Allocation Memory is not allocated or consumed when a class is defined. When an object of a class is instantiated, that is when memory is allocated.
Declaration/definition A class is declared only once. Typically a keyword like "class" is used to define it. Objects of a class may be instantiated as many times as needed. Typically instantiation happens via special methods called constructors.
Effect of modification If a class is modified, the change will apply to all objects of that class. e.g., if you add a new method to a class, all objects (existing and future) that belong to that class will have that method available to them. When an object is modified, the change does not apply to other objects of that class.

Special Cases

In some programming languages, e.g. Python, everything is an object. This means functions, variables, instances of a class and even actual classes are treated as objects by the programming language.

About the Author

Nick Jasuja

Nick Jasuja has over 15 years of technology industry experience, including at Amazon in Seattle. He is an expert at building websites, developing software programs in PHP and JavaScript, maintaining MySQL and PostgreSQL databases, and running Linux servers for serving high-traffic websites. He has a bachelor's degree in Computer Science & Engineering.

Share this comparison via:

If you read this far, you should follow us:

"Class vs Object." Diffen.com. Diffen LLC, n.d. Web. 14 Oct 2025. < >