OOP Studio Ages 9-15
Inheritance Builder
Students create a parent class, then build two child classes with different powers.
Build two special character types.
Example code
class Creature {
constructor(name) {
this.name = name;
}
move() {
say(this.name + " moves across the map.");
}
}
class Dragon extends Creature {
breatheFire() {
say(this.name + " breathes a tiny practice flame.");
}
}
class Unicorn extends Creature {
heal() {
say(this.name + " shares healing light.");
}
}
let dragon = new Dragon("Ember");
let unicorn = new Unicorn("Luna");
dragon.move();
dragon.breatheFire();
unicorn.move();
unicorn.heal();
Program result
- Run your code to see output.
Type real JavaScript, then run it.
Inheritance builder complete.
You used one parent class to share behavior with two different child classes.
Try Inheritance Challenge