Bootcamp Curriculum • 5 Modules • 12 Chapters • Multi-Language Runner (Python, JS, Java, C++) • Interactive Memory Trace • AI Mentor
CHAPTER 12 · OOP-BASICS7 min read

Object-oriented programming & classes

As software grows, grouping related data and functions together into Objects becomes essential. A Class acts as a reusable blueprint, while Objects are real instances built from that blueprint.

By the end of this chapter, you can:
  • Understand classes as blueprints and objects as instances.
  • Initialize attributes using the __init__() constructor.
  • Define methods that manipulate object state.
Explanation DepthTailor the level of detail to your learning goal
💻 Standard College Notes

Classes, __init__ constructor, instance attributes, and methods.

A class packages state (attributes) and behavior (methods) together. The __init__(self, ...) method initializes new instances. self represents the specific instance being operated on.

💡Every instance method must take self as its first parameter.

Classes, attributes, and methods in action

The `__init__()` constructor initializes state whenever a new instance is created. `self` refers to the specific instance being operated on.

example_1.py
Ctrl + ↵ to run
Terminal Output
Ready to execute
Click "▶ Run Code" or press Ctrl+Enter to compile & run this snippet.
✦ Interactive Dry-Run Visualizer

Memory Trace: Object Instantiation & Method Invocation

Follow how RAM instantiates class blueprints into heap objects.

STEP1 / 4
1bot = CyberBot("PodiaBot")👉 Executing
2bot.energy = 45
3bot.recharge(30)
4print(bot.energy)
VariableValue in MemoryData Type
bot.name"PodiaBot"auto
bot.energy100auto
Instantiate object from CyberBot class

RAM allocates heap memory for the new instance with self.name and self.energy.

Console Stream (stdout)
(No output generated yet)
Line 1: bot = CyberBot("PodiaBot")

🔧 Missing self in Class Method

A class method was defined without self, throwing TypeError when called on an instance.

⚡ +100 XP
fix_bug.pyPython 3.10
⚡ Quick Revision Quiz

Predict The Output (2 Questions)

Question 1 of 2:
What does `self` represent in an instance method?
Question 2 of 2:
What is the initialization method called in Python classes?

Your lightbulb moment

✧

The key takeaway
Object-oriented programming bundles state (attributes) and behavior (methods) into reusable blueprints called classes.

Make it yours

Try creating a second bot instance called bot2 and see how its energy state is completely independent from bot1.

Try editing the code in the playground above in Python, JavaScript, Java, or C++, and use the step-by-step Dry-Run Table to inspect how variables mutate in memory. If you get stuck, click the 🤖 AI Doubt Solver button on your screen for instant explanations!