Back to Collection Challenge
Advanced Objects · Lesson 1

Inheritance: Wizard Spell Academy

Help a Wizard use one power borrowed from a parent class and one power of its own.

10-15 minOOPMagic Training
What are you learning?

A child class does not have to rewrite everything. It can inherit a shared method from its parent, then add a new method of its own.

Parent: chargeMagic()Child: inherits itChild adds: castSpell()
When would this be used?

When different objects share the basics but need special powers.

Imagine a game with a Wizard, Healer, and Sorcerer. They all need a name, magic energy, and chargeMagic(). Put those shared features in MagicCharacter once. Then each child class adds only what makes it different.

Wizardinherits chargeMagic()adds castSpell()
Healerinherits chargeMagic()adds healTeam()
Sorcererinherits chargeMagic()adds summonStorm()

Rule of thumb: If you are copying the same properties or methods into several similar classes, a parent class may help.

1. Create the child.

Select Wizard extends MagicCharacter.

2. Borrow parent magic.

Run inherited chargeMagic().

3. Use Wizard magic.

Run child-only castSpell().

Choose the Correct Child
Shared magic orbMagicCharacterchargeMagic()Find the child that extends this parent

Start here: Which character extends MagicCharacter?

Your 3-Step Mission
1Select Wizard2Charge inherited magic3Cast Wizard spell

Step 1: Select the Wizard.

Wizard waiting to learn magicInherited charge magic orbWizard special spell orb

The Wizard has no active magic yet.

See the JavaScript connection
class Wizard extends MagicCharacter

Inheritance lets Wizard reuse the parent’s chargeMagic() method.