I am trying to clone a DTO. I took the DTO object as shown:
public class Employee implements Cloneable { String name; String dept; public String getName() { return name; } public void setName(String name) { this.name = name; } public String getDept() { return dept; } public void setDept(String dept) { this.dept = dept; } }
But this line gives me an error:
public class Test { public static void main(String args[]) { Employee emp1 = new Employee(); emp1.setDept("10"); emp1.setName("Kiran"); Employee emp2 = (Employee) emp1.clone();
My request is that the clone method is set to Object , so why can't we use it directly, how do we make the toString method?
source share