Back to Polymorphism
OOP Studio Ages 9-15

Polymorphism Builder

Build three versions of speak(), then send one shared command through the whole robo-pet team.

20-25 min Ages 9-15 OOP Builder JavaScript
1. Override

Give each child class its own speak() result.

2. Build the team

Put all three objects in one pets array.

3. Run one loop

The same command activates the correct behavior automatically.

Build speak() Overrides

Match each child class to its behavior.

Robo catRoboCatspeak() →
Robo dogRoboDogspeak() →
Robo rabbitRoboRabbitspeak() →
NEXT STEPChoose a speak() result for all three pets.
Live Pet Team

One loop visits every object.

pets[0]Robo catPixelRoboCatwaiting
pets[1]Robo dogBoltRoboDogwaiting
pets[2]Robo rabbitZippyRoboRabbitwaiting
Team not programmed yet

Build all three versions of speak().