練習題:程序員
public abstract class Employee { private int id; private String name; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public void eat() { System.out.println("該吃飯"); } public abstract void work(); } class programmer extends Employee { @Override public void work() { System.out.println("id : " + getId() + " 的 " + getName() + "寫代碼"); } } class Teacher extends Employee { @Override public void work() { System.out.println("id : " + getId() + " 的 " + getName() + "講課"); } } class Managert extends Employee { @Override public void work() { System.out.println("id : " + getId() + " 的 " + getName() + "拉網線"); } } class Test { public static void main(String[] args) { programmer pro = new programmer(); pro.setId(001); pro.setName("zxh" ); pro.work(); pro.eat(); } }