MyException - 我的异常网
当前位置:我的异常网» J2SE » 这个 JDK 程序 错了 求纠正! 恳请高手们指点解决

这个 JDK 程序 错了 求纠正! 恳请高手们指点解决方案

www.MyException.Cn  网友分享于:2013-12-29  浏览:2次
这个 JDK 程序 错了 求纠正!!!! 恳请高手们指点
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;
    }


}

文章评论

软件开发程序错误异常ExceptionCopyright © 2009-2015 MyException 版权所有