class shiyan10{
Employee e1,e2;
public shiyan10(){
e1=new Employee("wang",3000);
e1.addSalary(2);
System.out.println("name: "+e1.getname());
e1.getInfo();
System.out.println("Salary: "+e1.getSalary());
e2=new Employee("LI",2500);
e2.addSalary(1);
System.out.println("name: "+e2.getname());
e2.getInfo();
System.out.println("Salary: "+e2.getSalary());
}
public static void main(String arg){
new shiyan10();
}
}
public interface IEmployee{
public static final double prize=1000;
public abstract void addSalary();
}
class Employee implements IEmployee{
private String name;
private double Salary;
public Employee(String name,double Salary){
this.name=name;
this.Salary=Salary;
}
public String getname(){return name;}
public void getInfo(){System.out.println("I am Employee");}
public double getSalary(){return Salary;}
public void addSalary(int n){Salary+=prize*n;}
}
------解决方案--------------------
有好几个问题,你自己对比代码看看吧
- Java code
public class Shiyan10{ Employee e1,e2; public Shiyan10(){ e1=new Employee("wang",3000); e1.addSalary(2); System.out.println("name: "+e1.getname()); e1.getInfo(); System.out.println("Salary: "+e1.getSalary()); e2=new Employee("LI",2500); e2.addSalary(1); System.out.println("name: "+e2.getname()); e2.getInfo(); System.out.println("Salary: "+e2.getSalary()); } public static void main(String[] arg){ new Shiyan10(); }}interface IEmployee{ public static final double prize=1000; public abstract void addSalary(int n);}class Employee implements IEmployee{ private String name; private double salary; public Employee(String name,double Salary){ this.name=name; this.salary=Salary; } public String getname(){ return name; } public void getInfo(){ System.out.println("I am Employee"); } public double getSalary(){ return salary; } @Override public void addSalary(int n){ salary+=prize*n; }}