public class Accum { private int value = 0; // hidden public Accum() {} public void incr() { value ++; } public void twice() { value *= 2; } public int get() { return value; } public String toString() { return ""+value; } @Override public boolean equals(Object o) { if(o instanceof Accum) { // Safe to Cast Accum a = (Accum)o; // Cast return a.value == value; } return false; } public static void main(String[] args) { Accum m = new Accum(); m.incr(); m.incr(); m.twice(); System.out.println("m="+m); // something you think is true assert m.equals(new Accum()); }}