Skip to content
BENIBIX Learn

Class

Development🧭 Programming ParadigmsObject-Oriented Programming

Also known as Class (Programming), Class Definition

A plan for making objects. It lists their data and their actions.

Think of it like

Think of it like a cookie cutter. You make one cutter, then press out lots of cookies.

Example

Emma writes a Dog class with a name and a speak method. She makes a dog called Rex from it, and Rex says woof.

Why it matters

Classes let you write the shape of a thing once and reuse it everywhere.

Definition

A class is a plan for making objects of one kind, like dogs or players. It says what data each object will hold and what actions it can do. The class itself is just the plan; each object made from it is real and has its own values. In most languages a class name starts with a capital letter. You use the class name to make a new object.

Example code

python
class Dog:
    def __init__(self, name):
        self.name = name

    def speak(self):
        return self.name + " says woof"

rex = Dog("Rex")
print(rex.speak())  # Rex says woof
One plan called Dog, and one dog made from it.

Common mistake

Mixing up the class and the object. Dog is the plan; Rex is one dog.

Key takeaways

  1. 1
    A plan. Not a real thing yet.
  2. 2
    Data and actions. What each object holds and does.
  3. 3
    Many from one. Make as many as you need.

Compare