Java for Humans {Polymorphism}

Lincoln W Daniel
HackerNoon.com

--

View Table of Contents | Download Supporting Code | Subscribe to ModernNerd Youtube Channel for Coding Videos | By Lincoln W Daniel

In our short look at polymorphism at work in both the Class Inheritance and Abstract Classes & Interfaces chapters, we got a glimpse at how powerful polymorphism is. In both chapters, we learned that any object that can pass more than one is-a test, that is any object that is of more than one type, is considered polymorphic. With that said, we can define polymorphism as the ability of an object to take on more than one form.

Why is Polymorphism Important & Useful

Polymorphism is one of the most important concepts in object oriented programming. It is what allows us to say that all types in Java are the type of its class as well as the type of the Object class; we’ve learned that all objects in Java are instances of the Object class because of Java’s class hierarchy.

One Functionality for All

We learned in the Class Inheritance chapter that If we can say an instance of a class can be of more than one type, we can build functionality for one class that works for any class that extends it. We created a Human class that our Warrior, Archer, and FireArcher all inherited from. That allowed us to create methods that accepted them all as parameters because we could group them all as being Human. That is polymorphism at work.

One Collection for All

--

--

Lincoln W Daniel
HackerNoon.com

Chief Bull @ BullAcademy.org ® Elevating writers @ ManyStories.com. Author @JavaForHumans Ex: Editor in Chief MarkGrowth (acq.), Engineer @Medium @GoPuff