import java.util.ArrayList; class Hashing2 implements Cloneable{ private String s; int x; Hashing2(String s, int x) { this.s=s; this.x=x; } protected Object clone() { try { Hashing2 e = (Hashing2)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 Hashing2) ) return false; Hashing2 e2 = (Hashing2) o; return (x==e2.x && s.equals(e2.s)); } public int hashCode() { return x*5 + s.hashCode()*7; } public static void main(String [] args) { Hashing2 e = new Hashing2("Bonjour",12); Hashing2 f = (Hashing2)e.clone(); System.out.println("f: " + e.hashCode()); System.out.println("f: " + f.hashCode()); System.out.println("e==f? " + e.equals(f)); System.out.println(""); } public String toString() { return x + " " + s; } }