Polymorphism is the process or rather state in which something can take on multiple shapes and/or forms It’s derived from the Greek word “Poly” meaning many and “Morph” meaning shape.
Polymorphism with regards to Object Oriented programming
- Most of what I know about OOP is learned and experience with Java.
- Thanks to polymorphism, we can override and methods, and have objects be more than just their static type.
- It enable the PrincipleOfPolymorphicMethodDispatch which explains how an object that has a dynamic type that extends its static type (is a subclass of the superclass).
- If the method is overridden in the subclass, then that implementation is what gets executed
- If it’s not overridden then the version in the superclass is what get executed.
- During Polymorphic method dispatch, if the method isn’t overridden in the dynamic type, the JVM will go all up the hierarchy until it finds it or crashes the program if it can’t find it.