I have tried this implementation but i got false for the class x
x.clone().equals(x)
Class X :
public class X implements Cloneable{
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
protected Object clone()throws CloneNotSupportedException {
return super.clone();
}
}
Main class :
public class ObjectCloneCopy {
public static void main(String[] args) throws CloneNotSupportedException {
X x = new X();
System.out.println("x.clone().equals(x) - " + x.clone().equals(x));
}
}
Is it mandatory to overload the hashcode() and equals() to get this True ?
Without overriding these methods how this statement gives true?
X x1 = x;
x1.equals(x)
Explain how that could be true, i have seen in this link