OOP Studio Ages 9-15
Inheritance Challenge
Create a parent class and at least one child class that adds a new method.
Create your own special object.
Example code
class Tool {
constructor(name) {
this.name = name;
}
use() {
say("Using " + this.name + ".");
}
}
class MagicTool extends Tool {
glow() {
say(this.name + " glows with extra power!");
}
}
let wand = new MagicTool("Star Wand");
wand.use();
wand.glow();
Program result
- Run your code to see output.
Type real JavaScript, then run it.
Inheritance challenge complete.
You created a child class that inherits from a parent class and adds something new.
Next Lesson