Back to Polymorphism Builder
OOP Studio Ages 9-15

Polymorphism Challenge

Create at least two child classes that use the same method name in different ways.

10-15 min Ages 9-15 OOP Challenge JavaScript
Code Editor

Create your own shared method.

Example code
class Power {
  constructor(name) {
    this.name = name;
  }

  use() {
    say(this.name + " is used.");
  }
}

class SpeedPower extends Power {
  use() {
    say(this.name + " makes the hero zoom!");
  }
}

class ShieldPower extends Power {
  use() {
    say(this.name + " blocks the next hit!");
  }
}

let powers = [
  new SpeedPower("Lightning Boots"),
  new ShieldPower("Bubble Shield")
];

for (let power of powers) {
  power.use();
}
Output

Program result

Robot ready to speak your strings

Type real JavaScript, then run it.