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 ... |
Get PURE Java™ 2 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.