class Employee {
private String name;
private float salary;
public void setName(String name) {
this.name = name;
}
public String getName() {
System.out.println(this.name);
return this.name;
}
public void setSalary(float salary) {
this.salary = salary;
}
public float getSalary() {
System.out.println(this.salary);
return this.salary;
}
public static void main(String[] args) {
Employee emp = new Employee();
emp.setName("Lily");
emp.setSalary(350.0f);
Employee emp1 = new Employee();
emp1.setName("Lucy");
emp1.setSalary(3000.0f);
emp.getName();
emp1.getName();
emp.getSalary();
emp1.getSalary();
}
}
温馨提示,emp1.setSalary(3000.0f); java中float类型不加f,会报错;