© The Author(s), under exclusive license to APress Media, LLC, part of Springer Nature 2024
J. FriesenLearn Java Fundamentalshttps://doi.org/10.1007/979-8-8688-0351-2_8

8. Changing Type via Polymorphism

Jeff Friesen1  
(1)
Dauphin, MB, Canada
 

Some real-world entities can change their forms. For example, water (on Earth as opposed to interstellar space) is naturally a liquid, but it changes to a solid when frozen, and it changes to a gas when heated to its boiling point. Insects such as butterflies that undergo metamorphosis are another example.

The ability to change form is known as polymorphism and is useful to model in a programming language. For example, code that draws arbitrary shapes can be expressed more concisely by introducing a single Shape ...

Get Learn Java Fundamentals: A Primer for Java Development and Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.