9. Classes & OOP
1. Simple Definition & Meaning
Object-Oriented Programming (OOP) is a way of organizing code by creating Classes. A Class is like a blueprint or a mold, and Objects are the things you build using that mold.
2. Real-World Examples
- Example 1: A Class is the blueprint for a car. It says cars have 4 wheels and a color. An Object is YOUR actual red car parked outside.
- Example 2: A Class is a cookie cutter (star shape). The Objects are the actual cookies you bake and eat!
3. Important Points
- Create a class using the
classkeyword. - The
__init__()method is a special function that runs automatically when you create a new object. selfis used to make sure the object knows it is talking about itself!
📝 Exam Notes (Quick Revision)
- Class: A template for creating objects.
- Instance: An object created from a class.
- Inheritance: A child class can inherit attributes and methods from a parent class.