G.10.1. Abstract Superclass Employee
Class Employee
(Fig. G.16) provides methods earnings
and toString
, in addition to the get and set methods that manipulate Employee
’s instance variables. An earnings
method certainly applies generically to all employees. But each earnings calculation depends on the employee’s class. So we declare earnings
as abstract
in superclass Employee
because a default implementation does not make sense for that method—there isn’t enough information to determine what amount earnings
should return. Each subclass overrides earnings
with an appropriate implementation. To calculate an employee’s earnings, the program assigns to a superclass Employee
variable a reference to the employee’s object, then invokes the earnings
Get Android™ How to Program, Second Edition 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.