Computer ScienceProgrammingEasy

Class (OOP)

Also known as:typeblueprintprototype (loosely)

A class in object-oriented programming is a blueprint or template that defines the attributes (data fields) and methods (functions) common to all objects of that type. When a class is instantiated, it produces an object — a concrete instance that holds its own copy of the class's attributes. Classes enable code organisation by grouping related data and behaviour together, forming the foundational building blocks of OOP design.

Class vs Object — Key Differences

AspectClassObject
DefinitionBlueprint / templateInstance of a class
MemoryNo memory allocated at definitionMemory allocated on creation
CreationDeclared with `class` keywordCreated with `new` keyword (or constructor call)
CountDefined onceCan create many objects from one class
ExampleCar (blueprint)myCar = new Car()

Interactive Tools

Codecademy – Classes in Python

Open Tool

W3Schools – Java Classes and Objects

Open Tool

Khan Academy – Objects in JavaScript

Open Tool
Diagram showing a class as a template and objects as its instances

Wikimedia Commons, CC BY-SA

Related Terms

The word "class" derives from Latin "classis" meaning a group or division. In programming, it was introduced by Ole-Johan Dahl and Kristen Nygaard in Simula 67 (1967), the first language to feature classes, later popularised by Smalltalk and C++.

classoopobjectblueprintinstantiation