O'Reilly logo

PURE Java™ 2 by Kenneth Litwak

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

Polymorphism: Overriding Methods

It's common, when you create subclasses from a base class, to need to change the way a specific method is implemented. If your subclass modifies the method signature or behavior of a method that it inherits from a superclass (within certain limits), we call that method in the subclass an "overridden method." Let's look at an example in Listing 5.10.

Code Listing 5.10. An Example of a Superclass and a Subclass That Overrides a Method of the Superclass
 public class Book { public GregorianCalendar dueDate; public boolean checkOut() { dueDate = new GregorianCalendar(new SimpleTimeZone(-8 * 60 * 60 * 1000, zoneID)); // This is insufficient code // for making a proper GregorianCalendar // object, but it will serve ...

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