public class Employee implements Cloneable{
private String name ;
private double salary;
private Date date;
public Employee(String name, double salary) {
this.name = name;
this.salary = salary;
this.date = new Date();
}
public Employee clone() throws CloneNotSupportedException {
Employee employee = (Employee) super.clone();
employee.date = (Date) date.clone();
return employee;
}
public void setName(String name) {
this.name = name;
}
public void setSalary(double salary) {
this.salary = salary;
}
public void setDate(Date date) {
this.date = date;
}
}
```
```java
public class CloneTest {
public static void main(String[] args) throws CloneNotSupportedException {
var orignal = new Employee("fa", 11);
var clone = orignal.clone();
System.out.println(clone.getClass());
}
}
```
版权声明:本文为zhanglongdream原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。