Class and Object
Class (Blueprint)
Object (Real thing built from it)
What is a Class?
A Class is a blueprint/template used to create objects. It defines:
- Attributes (data) the object will hold.
- Methods (actions) the object can perform.
A class is not a real object, it's just a plan.
Example: Car Class (Blueprint)A Car class only lists what every car will have, no actual car exists yet.
- Attributes: brand, model, color, maxSpeed
- Methods: start(), drive(), stop(), park()
What is an Object?
An Object is a real instance created from a class. Many objects can be created from the same class, each with its own values.
Example: Objects from Car ClassTwo objects built from the same Car class, each holding its own values.
- Car 1: Toyota, Corolla, Red, 2024
- Car 2: Honda, Civic, Blue, 2023
Both cars come from the same Car class but hold different values.
Blueprint Analogy
Blueprint (Class)
Actual Houses (Objects)
Just like one house blueprint can build many houses, one class can create many objects.
Final Rule
- Class defines the structure and behaviour, it's the plan.
- Object is the actual instance built from that class.
Key Idea: Class = Blueprint, Object = the real thing.