class Dog extends Animal implements Comparable { public int compareTo( Dog other ) { if (this.getAge() < other.getAge()) { return -1; // Any negative number is good enough to satisfy the interface. } else if (this.getAge() == other.getAge()) { return 0; } else if (this.getAge() > other.getAge()) { return +1; // Any positive number will suffice. } else { System.err.println( "Shouldn't reach this far." ); return 0; // Better than returning a bad answer: Throw an exception. } } /** A Constructor when given a name and a sound. */ public Dog( String nom, String sound ) { super( nom, sound ); } /** The sound *most* dogs make. */ private static final String DEFAULT_SOUND = "arf"; /** A constructor given a name only. */ public Dog( String nom ) { this( nom, DEFAULT_SOUND ); // Call the two-argument constructor. } public String wagTail() { return name + ": " + "[OhBoyOhBoyOhBoy!]"; } public String speak() { return this.wagTail(); } }