Topic 7 · Object-Oriented Programming (HL)
Computer Science · Cheatsheet

Topic 7 · Object-Oriented Programming (HL)

Chapter 1 · Classes, objects & inheritance

📋 Reference · always available
Class
BLUEPRINT — defines attributes + methods. Does nothing on its own.
Object / Instance
Each separate THING created from a class. `d1 = Dog('Rex')`. Many objects per class.
__init__
Constructor — runs automatically when object is created. Sets up initial attributes via `self.x = ...`.
self
Reference to the current object. `self.name` is this object's name; different objects have different selves.
Attribute
Data stored INSIDE an object. e.g. self.balance, self.name. Each object has its own values.
Method
Function defined INSIDE a class. Called as `obj.method()`. First parameter is always `self`.
Inheritance
`class Sub(Super)` — Sub IS-A Super and inherits Super's attributes + methods.
Override
Subclass defines a method with the SAME NAME as the parent → subclass version is used for its objects.
Polymorphism
Same method call → different behaviour depending on object's actual class. Run-time resolution.
4 OOP pillars
Encapsulation · Abstraction · Inheritance · Polymorphism.