大神帮忙看下,为什么会出现这样的错

悲伤的阿木木丿 悲伤的阿木木丿 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
这个是没有问题的

import java.time.LocalDate;

public class EmpioleeTest {
public static void main(String[] ages){
Employee[] staff = new Employee[3];
staff[0] = new Employee("张三",7500,1999,1,10);
staff[1] = new Employee("李四",5500,1989,2,20);
staff[2] = new Employee("王五",6000,1997,10,9);
for(Employee e:staff){
e.raiseSalary(5);
}
for(Employee e:staff){
System.out.println("name="+e.getName()+",salary"+e.getSalary()+",hireDay"+e.getHireDay());
}
}

static class Employee{
private String name;
private int id;
private double salary;
private LocalDate hireDay;

public Employee(String n,double s,int year,int month,int day){
name = n;
salary = s;
hireDay= LocalDate.of(year,month,day);
}

public String getName() {
return name;
}

public double getSalary() {
return salary;
}

public LocalDate getHireDay() {
return hireDay;
}

public void setName(String name) {
this.name = name;
}

public void setSalary(double salary) {
this.salary = salary;
}

public void setHireDay(LocalDate hireDay) {
this.hireDay = hireDay;
}

public void raiseSalary(double byPercent){
double raise = salary*byPercent/100;
salary+=raise;
}
}
}



这个是有问题的
import java.time.LocalDate;

public class EmpioleeTest {
public static void main(String[] ages){
Employee[] staff = new Employee[3];
staff[0] = new Employee("张三",7500,1999,1,10);
staff[1] = new Employee("李四",5500,1989,2,20);
staff[2] = new Employee("王五",6000,1997,10,9);
for(Employee e:staff){
e.raiseSalary(5);
}
for(Employee e:staff){
System.out.println("name="+e.getName()+",salary"+e.getSalary()+",hireDay"+e.getHireDay());
}
}

class Employee{
private String name;
private int id;
private double salary;
private LocalDate hireDay;

public Employee(String n,double s,int year,int month,int day){
name = n;
salary = s;
hireDay= LocalDate.of(year,month,day);
}

public String getName() {
return name;
}

public double getSalary() {
return salary;
}

public LocalDate getHireDay() {
return hireDay;
}

public void setName(String name) {
this.name = name;
}

public void setSalary(double salary) {
this.salary = salary;
}

public void setHireDay(LocalDate hireDay) {
this.hireDay = hireDay;
}

public void raiseSalary(double byPercent){
double raise = salary*byPercent/100;
salary+=raise;
}
}
}

我想知道,为啥在class Employee 前面少了一个static,就会报错
...全文

相关推荐

评论 8
收藏 已收藏
分享
返回顶部
悲伤的阿木木丿
Java SE 62,620 成员 307,251 内容