/*
A:案例演示
* 需求:定义一个员工类Employee
* 自己分析出几个成员,然后给出成员变量
* 姓名name,工号id,工资salary
* 构造方法,
* 空参和有参的
* getXxx()setXxx()方法,
* 以及一个显示所有成员信息的方法。并测试。
* work
*/
class Test_Employee {
public static void main(String[] args) {
Employee e1 = new Employee();
e1.setName(“张三”);
e1.setId(“007”);
e1.setSalary(5000);
e1.work();
Employee e2 = new Employee(“李四”,”008″,6000);
e2.work();
}
}
class Employee {
private String name;
private String id;
private double salary;
public Employee(){}
public Employee(String name, String id, double salary) {
this.name = name;
this.id = id;
this.salary = salary;
}
public void setName(String name) {
this.name =name;
}
public String getName() {
return name;
}
public void setId(String id) {
this.id = id;
}
public String getId() {
return id ;
}
public void setSalary(double salary) {
this.salary = salary;
}
public double getSalary () {
return salary;
}
public void work() {
System.out.println(name + “的工号是:” + id + “工资为:” + salary);
}
}
评论前必须登录!
注册