- /*
- 需求:公司中程序员有姓名,工号,薪水,工作内容。
- 项目经理除了有姓名,工号,薪水,还有奖金,工作内容。
- 思路:共性内容(员工) 姓名,工号,薪水
- 共有但内容不同: 工作内容
- 不同的地方:奖金
- 所以定义一个员工类
- 成员变量:姓名,工号,薪水
- 成员方法:工作内容(内容不同,用抽象)
- 程序员简单的继承,经理继承外加奖金
- */
- abstract class Employee
- {
- //姓名
- private String name;
- //工号
- private int workNumber;
- //薪水
- private double salary;
- Employee(){}
- Employee(String name,int workNumber,double salary){
- this.name = name;
- this.workNumber = workNumber;
- this.salary = salary;
- }
- public void setName(String name){
- this.name = name;
- }
- public void setWorkNumber(int workNumber){
- this.workNumber = workNumber;
- }
- public void setSalary(double salary){
- this.salary = salary;
- }
-
- public String getName(){
- return name;
- }
- public int getWorkNumber(){
- return workNumber;
- }
- public double getSalary(){
- return salary;
- }
- public abstract void work();
- }
- class Programmer extends Employee
- {
- Programmer(){}
- Programmer(String name,int workNumber,double salary){
- super(name,workNumber,salary);
- }
- public void work(){
- System.out.println("孜孜不倦的打代码");
- }
- }
- class Manager extends Employee
- {
- private double jiangJin;
- Manager(){}
- Manager(String name,int workNumber,double salary,double jiangJin){
- super(name,workNumber,salary);
- this.jiangJin = jiangJin;
- }
- public void setJiangJin(double jiangJin){
- this.jiangJin = jiangJin;
- }
-
- public double getJiangJin(){
- return jiangJin;
- }
-
- public void work(){
- System.out.println("坐在办公室吹空调");
- }
- }
复制代码 |
|