用java实现一个名为Person的类和它的子类Employee,ExcellentEmploye
用java实现一个名为Person的类和它的子类Employee,ExcellentEmployee是Employee的子类,设计一个接口Add用于涨工资,普通员工一次能...
用java实现一个名为Person的类和它的子类Employee,ExcellentEmployee是Employee的子类,设计一个接口Add用于涨工资,普通员工一次能涨10%,优秀员工一次能涨20%
展开
1个回答
展开全部
public abstract class Person {
public abstract int add();
}
public class Employee extends Person {
protected int num;
public Employee(){}
public Employee(int num){
this.num=num;
}
public int add(){
num*=(1+0.1);
return num;
}
}
public class ExcellentEmployee extends Employee{
public ExcellentEmployee(int num){
super.num=num;
}
public int add(){
num*=(1+0.2);
return num;
}
}
public class test {
public static void main(String[] args) {
Person employee = new Employee(10);
Person excellentEmployee = new ExcellentEmployee(10);
System.out.println("普通员工工资="+employee.add());
System.out.println("优秀员工工资="+excellentEmployee.add());
}
}
public abstract int add();
}
public class Employee extends Person {
protected int num;
public Employee(){}
public Employee(int num){
this.num=num;
}
public int add(){
num*=(1+0.1);
return num;
}
}
public class ExcellentEmployee extends Employee{
public ExcellentEmployee(int num){
super.num=num;
}
public int add(){
num*=(1+0.2);
return num;
}
}
public class test {
public static void main(String[] args) {
Person employee = new Employee(10);
Person excellentEmployee = new ExcellentEmployee(10);
System.out.println("普通员工工资="+employee.add());
System.out.println("优秀员工工资="+excellentEmployee.add());
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询