这个是没有问题的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,就会报错
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,就会报错
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货