- abstract class YuanGong
- {
- private String name;
- private String id;
- private int salary;
- public YuanGong(){}
- public YuanGong(String name, String id, int salary)
- {
- this.name = name;
- this.id = id;
- this.salary = salary;
- }
- public String getName()
- {
- return name;
- }
- public void setName(String name)
- {
- this.name = name;
- }
- public String getId()
- {
- return id;
- }
- public void setId(String id)
- {
- this.id = id;
- }
- public int getSalary()
- {
- return salary;
- }
- public void setSalary(int salary)
- {
- this.salary = salary;
- }
- public abstract void work();
- }
- class Worker extends YuanGong
- {
- public Worker(){}
- public Worker(String name, String id, int salary)
- {
- super(name,id,salary);
- }
- public void work()
- {
- System.out.println("按照需求写代码");
- }
- }
- class Manager extends YuanGong
- {
- private int money;
- public Manager(){}
- public Manager(String name, String id, int salary, int money)
- {
- super(name,id,salary);
- this.money = money;
- }
- public int getMoney()
- {
- return money;
- }
- public void setMoney(int money)
- {
- this.money = money;
- }
- public void work()
- {
- System.out.println("跟客户谈需求");
- }
- }
- class AbstractTest4
- {
- public static void main (String [] args)
- {
- YuanGong y = new Worker("小明","00002",15000);
- System.out.println(y.getName()+":"+y.getId()+":"+y.getSalary());
- y.work();
- System.out.println("===================");
- Manager y2 = new Manager("大明","00001",20000,10000);
- System.out.println(y2.getName()+":"+y2.getId()+":"+y2.getSalary()+":"+y2.getMoney());
- y2.work();
- }
- }
复制代码 |