एक क्लास एक नक्सा वा टेम्प्लेट हो जसले संरचना (fields) र व्यवहार (methods) परिभाषित गर्छ। एक वस्तु (वा instance) त्यो नक्साबाट बनेको ठोस कुरा हो, जसको मेमोरीमा आफ्नै मान हुन्छ।
नक्सा विरुद्ध instance
text
class Car ← ONE definition (the blueprint)
│ fields: color, speed
│ methods: accelerate()
▼
new Car("red") ← many OBJECTS (instances), each with its own state
new Car("blue")
कोडमा
python
:
():
.color = color
.speed =
():
.speed +=
a = Car()
b = Car()
a.accelerate()
(a.speed, b.speed)
(a.color b.color)
