- class AbstractEmployee{
- public static void main(String[] args) {
- Programmer P=new Programmer("张三",8888888,20000);
- P.work();
- P.speak();
- Manager M =new Manager("李四",888888,333333333,50000);
- M.work();
- M.speak();
- }
- }
- /*雇员(Employee)示例:
- 需求:公司中程序员(programmer)有姓名(name),工号(id),薪水(pay),工作内容(work)。
- 项目经理(Manager)除了有姓名(name),工号(id),薪水(pay),还有奖金(bonus),工作内容(work)。
- 对给出需求进行数据建模。*/
- abstract class Employee{
- String name;
- int id;
- double pay;
- public abstract void work();
- Employee(){}
- Employee(String name,int id,double pay){
- this.name = name;
- this.id = id;
- this.pay = pay;
- }
- public void speak(){
- System.out.println(name+" "+id+"号"+pay+"元");
- }
- }
- class Programmer extends Employee{
- public void work(){
- System.out.println("按照上级要求敲出代码");
- }
- Programmer(){}
- Programmer(String name,int id,double pay){
- super(name,id,pay);
- }
- }
- class Manager{
- double bonus;
- public void work(){
- System.out.println("分析需求,给程序员下达任务");
- }
- Manager(){}
- Manager(String name,int id,double pay,double bonus){
- super(name,id,pay);
- this.bonus=bonus;
- }
- }
复制代码 |