ਇੱਕ ਕਲਾਸ ਇੱਕ ਨਕਸ਼ਾ ਜਾਂ ਟੈਮਪਲੇਟ ਹੈ ਜੋ ਬਣਤਰ (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)
