日期:2014-05-20  浏览次数:29503 次

这个怎么运行不成?请哪位大侠帮一下,谢谢!
public class Employee{
  private int id;
  private String name;
  private String department;
  private double salary;
  public String getDepartment(){
  return department;
  }
  public void setDepartment(String department){
  this.department=department;
  }
  public int getId(){
  return id;
  }
  public void setId(int id){
  this.id=id;
  }
  public String getName(){
  return name;
  }
  public void setName(){
  this.name=name;
  }
  public double getSalary(){
  return salary;
  }
  public void setSalary(double salary){
  this.salary=salary;
  }
}

------解决方案--------------------
java应用程序要运行必须要有public static void main(String[])类型的主函数入口,你这个程序没有,所以无法运行
给你贴个能跑的
Java code

public class Employee{
    private int id;
    private String name;
    private String department;
    private double salary;
    public String getDepartment(){
        return department;
    }

    @Override
    public String toString() {
        return "Employee{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", department='" + department + '\'' +
                ", salary=" + salary +
                '}';
    }

    public void setDepartment(String department){
        this.department=department;
    }
    public int getId(){
        return id;
    }
    public void setId(int id){
        this.id=id;
    }
    public String getName(){
        return name;
    }
    public void setName(String name){
        this.name=name;
    }
    public double getSalary(){
        return salary;
    }
    public void setSalary(double salary){
        this.salary=salary;
    }

    public static void main(String[] args){
          Employee e=new Employee();
          e.setId(1);
          e.setName("demo1");
          e.setSalary(1000.0);
          System.out.println(e);
    }
}