O'Reilly logo

Sams Teach Yourself Object Oriented Programming in 21 Days, Second Edition by Anthony Sintes

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 7. Polymorphism: Time to Write Some Code

Yesterday you learned about polymorphism. You should have a good understanding of the four different types of polymorphism. Today you will gain hands-on experience with polymorphism through a number of lab exercises. By the end of today’s lesson, you should feel a bit more comfortable with the theory presented in Day 6, “Polymorphism: Learning to Predict the Future.”

Today you will learn

  • How to apply the different forms of polymorphism

  • How to write future proof software

  • How polymorphism can help you avoid switch logic

Lab 1: Applying Polymorphism

In Day 5, Lab 2 introduced you to an employee hierarchy. Listing 7.1 presents a slightly altered Employee base class.

Example 7.1. Employee.java

public abstract ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required