interface Set { ... } Set set = new Set(); // Error!! -- can't create interface object
class HashSet implements Set { ... } Set set = new HashSet();
abstract class Employee { Employee(Name name, String ssNum) {...} ...abstract void doPayroll();
... Name name; String ssNum; Date hiredOn; } class FactoryWorker extends Employee { FactoryWorker(Name name, String ssNum, Currency hourlyRate) { super(name, ssNUm); this.hourlyRate = hourlyRate; } ...void doPayroll() { ... }
... ... double hourlyRate; } class OfficeWorker extends Employee { OfficeWorker(Name name, String ssNum, Currency annualSalary) { super(name, ssNUm); this.annualSalary = annualSalary; } ...void doPayroll() { ... }
... Currency annualSalary; }
OfficeWorker
and
FactoryWorker
) will supply the additional state/behavior to
perform payroll in the proper manner.
Employee employee = new Employee(); // Error!! -- can't create abstract class object
Employee employee = new OfficeWorker(...);