This is the second article in a series I'm doing called DevBits. These are mini-articles that show how object-oriented programming concepts can be applied.
You’re making an RPG.
You have a Character
(class) who has health
(field).
A Character
can move()
or attack()
(methods).
A Player
(child class) is a type of Character
, but also has experience
(field).
An Enemy
(child class) is a type of Character
, but also has loot
(field).
Player
and Enemy
both share the same fields and methods from Character
, but can have any additional fields of their own.
This is inheritance.
Top comments (0)