ایک کلاس ایک نقشہ یا template ہے جو structure (fields) اور behavior (methods) کی تعریف کرتی ہے۔ ایک آبجیکٹ (یا instance) اس نقشے سے بنی ہوئی ایک concrete چیز ہے، جس کی اپنی memory میں values ہوں۔
نقشہ بمقابلہ 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)
