1 changed files with 25 additions and 0 deletions
@ -0,0 +1,25 @@ |
|||
public class EmployeeTest { |
|||
public static void main(String[] args) { |
|||
// 创建两个Employee对象,包括公司名
|
|||
Employee emp1 = new Employee("E001", "张三", "技术部", 8000.0, "湖南大学有限公司"); |
|||
Employee emp2 = new Employee("E002", "李四", "人事部", 1800.0, "湖南大学有限公司"); |
|||
|
|||
// 演示属性的访问,输出所有员工信息
|
|||
System.out.println("=== 所有员工信息 ==="); |
|||
System.out.println(emp1); |
|||
System.out.println(emp2); |
|||
|
|||
// 演示属性的修改
|
|||
System.out.println("\n=== 修改员工属性 ==="); |
|||
emp1.setDepartment("研发部"); |
|||
System.out.println("张三修改部门后:" + emp1); |
|||
|
|||
System.out.println("\n尝试修改李四工资为1500:"); |
|||
emp2.setSalary(1500.0); |
|||
System.out.println("李四修改后工资:" + emp2.getSalary()); |
|||
|
|||
// 验证静态变量共享性(修改后所有实例同步更新)
|
|||
System.out.println(emp1); |
|||
System.out.println(emp2); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue