public class Employee {
private String name;
private int age;
private float salary;
public Employee(String n, int i) {
this.name = n;
this.age = i;
}
public float getSalary() {
this.salary = 3000 + this.age * 20;
return this.salary;
}
public static void main(String[] args) {//主方法应该加在主类当中
Employee e1 = new Manager("张三", 40);
Employee e2 = new Worker("李四", 24);
}
}
class Manager extends Employee {
private float allance = 300;
public Manager(String n, int i) {
super(n, i);
System.out.print("经理工资为" + (super.getSalary() + this.allance) + "\n");
}
}
class Worker extends Employee {
private float allance = 1000;
public Worker(String n, int i) {
super(n, i);
System.out.print("工人工资为" + (super.getSalary() + this.allance) + "\n");
}
}
//看代码应该就可以理解了,有不懂随时欢迎追问