需求一:
项目经理类
属性:姓名 工号 工资 奖金
行为:工作work
程序员类
属性:姓名 工号 工资
行为:工作work
public class Demo1 {
public static void main(String[] args) {
Programmer p=new Programmer("123", "153", 5222);//创建程序员对象
p.work();//调用工作的方法
Article a=new Article("56", "56", 3000, 5000);//创建项目经理对象
a.work();//调用工作的方法
}
}
class Woker{
private String name;//姓名
private String num;//工号
private float salary;//工资
public Woker() {
}
public Woker(String name, String num, float salary) {
this.name = name;
this.num = num;
this.salary = salary;
}
//工作work
public void work(){
System.out.println(this.name+"工作");
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getNum() {
return num;
}
public void setNum(String num) {
this.num = num;
}
public double getSalary() {
return salary;
}
public void setSalary(float salary) {
this.salary = salary;
}
}
class Programmer extends Woker {
public Programmer() {
super();
}
public Programmer(String name, String num, float salary) {
super(name,num,salary);
}
}
class Article extends Woker {
private float bonus;//奖金
public Article() {
super();
}
public Article(String name, String num, float salary,float bonus) {
super(name,num,salary);
this.bonus=bonus;
}
} |
|