hi im trying to make a simple deep cloning example in java
public class Deepcloning implements Cloneable
{
public Shallowcloning shallowcopy;
public Deepcloning() {
}
public Shallowcloning getShallowcopy() {
return shallowcopy;
}
public void setShallowcopy(Shallowcloning shallowcopy) {
this.shallowcopy = shallowcopy;
}
public String getEmployee() {
return employee;
}
public void setEmployee(String employee) {
this.employee = employee;
}
private String employee;
public Object clone() throws CloneNotSupportedException{
Deepcloning shls=(Deepcloning)super.clone();
shls.setShallowcopy((Shallowcloning)shallowcopy.clone());
return shls;
}
}
and in the main implementation method
public class Clonningimplementation {
public static void main(String[] args) {
try {
Deepcloning dp1 = new Deepcloning();
dp1.setEmployee("solomon");
dp1.getShallowcopy().setAge(11);
dp1.getShallowcopy().setSalary(3000);
System.out.println("orignal copy employee" + dp1.getEmployee());
System.out.println("orignal copy employee" + dp1.getShallowcopy().getAge());
System.out.println("orignal copy employee" + dp1.getShallowcopy().getSalary());
} catch (ClonenotSupportedException e) {
e.printstacktrace();
}
...
}
...
}
while running this code im getting null pointer exception. in deep cloning im supposed to clone the reference that too i have done still didnt getting the result any help would be appreciated