クラス は構造(フィールド)と動作(メソッド)を定義する テンプレート または設計図です。オブジェクト(または インスタンス)はそのテンプレートから作られた具体的なもので、メモリに独自の値を持ちます。
なぜ重要なのか
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)
