© Edward Sciore 2019
Edward ScioreJava Program Designhttps://doi.org/10.1007/978-1-4842-4143-1_2

2. Polymorphism

Edward Sciore1 
(1)
Newton, MA, USA
 

Each class in a well-designed program denotes a distinct concept with its own set of responsibilities. Nevertheless, it is possible for two (or more) classes to share some common functionality. For example, the Java classes HashMap and TreeMap are distinct implementations of the concept of a “map,” and both support the methods get, put, keySet, and so on. The ability of a program to take advantage of this commonality is known as polymorphism .

This chapter explores the use of polymorphism in Java. Java supports polymorphism via the concept of an interface. All the techniques in this chapter use interfaces. ...

Get Java Program Design: Principles, Polymorphism, and Patterns 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.