Getting Started with Java
This is a 100% free course, but we need you to first join or login to watch this video.
Alright, join or login here.This video shows an example of polymorphism or dynamic method dispatch in Java. We have a base class called Shape with several subclasses such as Square, Circle, Rectangle, Triangle and they all override the base method getArea() to define how each of their areas are calculated. The main program asks the user to enter the side lengths for a bunch of different shapes and then calculates the minimum, maximum and average area using polymorphism.