Grokking Advanced JavaScript
Vote

0% completed

​

Polymorphism

The same line of code, vehicle.refuel(), prints three different messages in the program below. The line does not change; only the object stored in vehicle changes, and each object carries its own version of refuel().

When one call can run different code depending on the object that receives it, the behavior is called polymorphism. The word comes from Greek and means "many forms": one operation, many forms of carrying it out. The diagram shows the program that follows. Notice that the highlighted line `vehicle.refuel()

.....

.....

.....

Like the course? Get enrolled and start learning!

Reading Progress

0%


Vote for new content