public static void main(String[] args) { /*Employee e = new Employee("王八",22222,20000); //有参构造方法的调用 e.work();*/ Employee e = new Employee(); //set和get方法的调用 e.setName("里斯"); e.setId(33333); e.setSalary(20000); e.work(); /*System.out.println(e.getName() + e.getId() + e.getSalary());*/ } } class Employee { //员工类 private String name ; //成员变量的私有化 private int id; private double salary; public Employee() {} //无参构造方法 public Employee(String name,int id,double salary) { //有参构造方法 this.name = name ; this.id = id ; this.salary = salary; } public void setName(String name) { //成员变量的set和get的方法 this.name = name; } public String getName() { return this.name; } public void setId(int id) { this.id = id; } public int getId() { return this.id; } public void setSalary(double salary) { this.salary = salary; } public double getSalary() { return this.salary; } public void work() { //定义work方法用来返回值 System.out.println("我的名字是:" + name + ",我的id是:" + id + ",我的工资是:" + salary + "."); } } |