这是根据你写的改的- public class Demo2 {
- public static void main(String[] args)
- {
- //程序员
- Developer dp = new Developer("王强",10110,5000);
- dp.work();
- dp.show();
- //项目经理
- ProjectManager pm = new ProjectManager("刘东",10001,8000,10000);
- pm.show();
- pm.work();
- }
- }
- abstract class Worker
- {
- private String name;
- private int number;
- private int pay;
-
- Worker(String name,int number,int pay)
- {
- this.name=name;
- this.number=number;
- this.pay=pay;
- }
- /**
- * @return the name
- */
- public String getName() {
- return name;
- }
- /**
- * @param name the name to set
- */
- public void setName(String name) {
- this.name = name;
- }
- /**
- * @return the number
- */
- public int getNumber() {
- return number;
- }
- /**
- * @param number the number to set
- */
- public void setNumber(int number) {
- this.number = number;
- }
- /**
- * @return the pay
- */
- public int getPay() {
- return pay;
- }
- /**
- * @param pay the pay to set
- */
- public void setPay(int pay) {
- this.pay = pay;
- }
-
- public abstract void show();
- public abstract void work();
- }
- class Developer extends Worker
- {
- Developer(String name,int number,int pay)
- {
- super(name,number,pay);
- }
-
- public void show()
- {
- System.out.println("姓名:"+getName()+"工号:"+getNumber()+"薪水:"+getPay());
- }
- public void work()
- {
- System.out.println("程序员编写程序");
- }
- }
- class ProjectManager extends Worker
- {
- private int reward;
- ProjectManager(String name,int number,int pay,int reward)
- {
- super(name,number,pay);
- this.reward=reward;
- }
- /**
- * @return the reward
- */
- public int getReward() {
- return reward;
- }
- /**
- * @param reward the reward to set
- */
- public void setReward(int reward) {
- this.reward = reward;
- }
- public void show()
- {
- System.out.println("姓名:"+getName()+"工号:"+getNumber()+"薪水:"+getPay()+"奖金:"+getReward());
- }
- public void work()
- {
- System.out.println("项目经理负责管理项目开发实施");
- }
-
- }
复制代码 |