ตัวอย่างที่ไม่ใช่สัตว์เลี้ยงลูกด้วยนมที่ไม่ใช่นกและไม่ใช่ปลานี้อาจช่วย:
public abstract class Person {
/* this contains thing all persons have, like name, gender, home addr, etc. */
public Object getHomeAddr() { ... }
public Person getName() { ... }
}
public class Employee extends Person{
/* It adds things like date of contract, salary, position, etc */
public Object getAccount() { ... }
}
public abstract class Patient extends Person {
/* It adds things like medical history, etc */
}
แล้วก็
public static void main(String[] args) {
/* you can send Xmas cards to patients and employees home addresses */
List<Person> employeesAndPatients = Factory.getListOfEmployeesAndPatients();
for (Person p: employeesAndPatients){
sendXmasCard(p.getName(),p.getHomeAddr());
}
/* or you can proccess payment to employees */
List<Employee> employees = Factory.getListOfEmployees();
for (Employee e: employees){
proccessPayment(e.getName(),e.getAccount());
}
}
หมายเหตุ: อย่าบอกความลับ: บุคคลขยาย Mammal