From the course: Java Object-Oriented Programming

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

What is polymorphism?

What is polymorphism?

- [Instructor] Polymorphism is the ability for an object or function to take many forms. Depending on the context and situation, the form may be different, making your code more flexible and reducing complexity. In fact, we've already started using it in this course, even if we didn't realize it. If we look at our example from the previous challenge, the ModArrayList instance takes a few different forms. When we use its getUsingMod functionality, we are using it in the form of a ModArrayList. However, when we use the add functionality, we're using it as an array list. In fact, if we click into the add functionality, it won't take me to the ModArrayList class, rather the ArrayList class. This is where that functionality is defined. The idea that an object can use functionality from different classes depending on the context is a key idea that's essential to understanding polymorphism. Java supports two types of…

Contents