import java.util.ArrayList; class Equals2 implements Cloneable{ private String s; int x; Equals2(String s, int x) { this.s=s; this.x=x; } protected Object clone() { try { Equals2 e = (Equals2)super.clone(); e.s=new String(s); return e; } catch (CloneNotSupportedException e) { throw new Error("This should not happen since we implemented Cloneable"); } } public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof Equals2) ) return false; Equals2 e2 = (Equals2) o; return (x==e2.x && s.equals(e2.s)); } public static void main(String [] args) { Equals2 e = new Equals2("Bonjour",12); Equals2 f = (Equals2)e.clone(); System.out.println("f: " + e); System.out.println("f: " + f); System.out.println("e==f? " + e.equals(f)); System.out.println(""); } public String toString() { return x + " " + s; } }