Introduction and Implementation of Polymorphism
Learn about the polymorphism principle and how to implement it.
We'll cover the following
What is polymorphism?
According to the polymorphism principle (“poly” is the Greek word for “many”), methods in different classes that do similar things should have the same name.
A prime example is that of classes that represent geometric shapes (such as rectangles, circles, and octagons) which are different from each other in the number of sides and in the formula that calculates their area but all have an area in common that needs to be calculated. In such a case, the polymorphism principle says that all the methods that calculate the area (it doesn’t matter for which shape or class) should have the same name.
Get hands-on with 1400+ tech skills courses.