2.1.1 · HinglishOOP Fundamentals
Class vs object — blueprint vs instance
2.1.1· Coding › OOP Fundamentals
HUM kis baare mein baat kar rahe hain?
YEH distinction kyun exist karti hai?
Blueprint ko instance se alag kyun kiya jaata hai?
- Reuse — description ek baar likho, bahut saare objects stamp karo.
- Independent state — har object apna data rakhta hai; ek ko change karne se doosre corrupt nahi hote.
- Shared behaviour — methods ek baar (class par) store hoti hain, isliye 1000 objects mein se har ek code ki 1000 copies store nahi karta.
Inhe kaise banate aur use karte hain?
class Dog: # blueprint begins
species = "Canis" # CLASS attribute (shared by all dogs)
def __init__(self, name, age): # the constructor
self.name = name # INSTANCE attribute (per object)
self.age = age
def bark(self): # behaviour
return f"{self.name} says Woof!"
d1 = Dog("Rex", 3) # instantiation -> an OBJECT
d2 = Dog("Fido", 5) # another OBJECT, independent stateInstantiation step by step kaise kaam karta hai:
Dog("Rex", 3)Python se request karta hai kiDogtype ka ek blank object create karo.- Python
__init__ko call karta hai jahanself= naya blank object hota hai. self.name = namedata ko us object mein likhta hai.- Taiyaar object ka reference wapas hand over ho jaata hai aur
d1mein store ho jaata hai.

Worked Examples
Common Mistakes
Recall Feynman: 12-saal ke bacche ko samjhao
Ek class cookie cutter ki tarah hai. Cutter khud cookie nahi hai — woh shape hai. Jab bhi tum usse dough mein press karte ho tum ek cookie (object) paate ho. Saari cookies ka same shape hota hai (same class), lekin tum har ek par alag toppings daal sakte ho (alag data). Ek cookie phenkne se doosri ko kuch nahi hota, aur tumhare paas zyada cookies banane ke liye cutter abhi bhi hai.
Flashcards
Class kya hoti hai?
Ek blueprint/template jo data (attributes) aur behaviour (methods) bundle karta hai; yeh kisi cheez ka description deta hai lekin khud runtime instance nahi hota.
Object kya hota hai?
Ek concrete instance jo class se bana ho, memory occupy karta ho, aur instance attributes ki apni copy rakhta ho.
Instantiation kya hai?
Class se object create karne ki act, jaise
Dog("Rex", 3), jo __init__ trigger karta hai.Instance attributes kahan rehte hain?
Individual object par (via
self.x = ... likhe jaate hain), har object ke liye alag.Class attributes kahan rehte hain?
Class par khud, saare instances ke beech shared, jab tak kisi instance par shadow na ho jaayein.
d1.age change karne se d2.age kyun affect nahi hota?
Har object ke paas instance attributes ke liye apni independent memory hoti hai.
Do equal-dikhte objects ke liye a is b kya test karta hai?
Identity (same memory location) — yeh False hoga do alag se instantiate kiye objects ke liye chahe data equal ho.
Class likhne se koi object create hota hai kya?
Nahi — yeh sirf ek blueprint define karta hai; objects tab aate hain jab tum class ko call karte ho.
Methods class par kyun store hoti hain, har object par kyun nahi?
Code ki ek copy saare instances ke beech share karne ke liye, memory bachane ke liye.
Connections
- Constructors and __init__ — instantiation par object kaise initialise hota hai.
- self and instance methods —
selfmethods ko ek specific object se kaise bind karta hai. - Class vs instance attributes — shared-vs-own data ka distinction.
- Encapsulation — class mein data+behaviour bundle karna kyun matter karta hai.
- Identity vs Equality (is vs ==) — objects ko distinguish karna.
- Memory model and references — objects actually kahan rehte hain.