大神帮忙看下,为什么会出现这样的错
这个是没有问题的
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,就会报错
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,就会报错
...全文
相关推荐
MATLAB图像错切_matlab_图像处理_水平错切_图像错切_
**创建错切矩阵**:定义错切因子,然后构建变换矩阵。
为什么2440与SDRAM地址线错两位相连?
为什么2440与SDRAM地址线错两位相连? 网上说,错两位是为了32位对齐(地址为8位数据地址,2440位宽为32,错两位,跳4byte)。 下面是听南方大哥的教程时记录的: 由于两个内存合起
朝文打字练习软件,有需要的看下
朝文打字练习软件,有需要的看下。想学韩文打字的来看下,还是不错的 。
学习WPA啊看下就知道了
看下就知道了,你不看你就白经过了。来了就下下看啊。不要钱
【对与错阅读答案】对与错阅读理解.docx
他的小脸上写满了不满和疑惑,似乎在质问我为什么没有人指出来。我随口应道,这不过是装饰品,没必要过分纠结。但我心里却感到一阵说不出的复杂。“稚嫩”这个词来形容小侄子再合适不过。


Java SE
