DEV Community

Discussion on: What is Polymorphism? - Explaining Polymorphism to a Five Year Old

Collapse
snickdx profile image
Nicholas Mendez

Because you can't typecast helicopter objects as aircraft objects, I'd argue your example cannot apply polymorphism in the true sense of the term. Inheritance is the key a was shown in the OP while what you showed composition.

Collapse
lukeshiru profile image
LUKESHIRU

You can use helicopter in any place you use aircraft, because they have the same methods (as noted by ...aircraft). You can see it working in TS as well if you want, here. It is closer to composition, but the comment mainly highlights that polymorphism is not something that you can only achieve with classes.