/* SimpleSubclasses/Ant.java A very simple class, with one field added to superclass Animal: */ public class Ant extends Animal { double poisonStrength; // strength of poison, 0 to 1 // constructors Ant () { // create with defaults provided weight = 0.5; x = 0; y = 0; poisonStrength = 1.0; } ////////////////////////////////////////////////////////////////////// // move -- override the inherited move method from animals public void move () { System.out.printf( "Ant at x=%d, y=%d moving...\n", x, y ); } // sting // ants can sting... public void sting () { System.out.printf( "Ant at x=%d, y=%d stinging (poison=%.2f)...\n", x, y, poisonStrength ); } public void printSelf () { System.out.printf( "Ant x=%d, y=%d, weight = %.2f, poisonStr = %.2f\n", x, y, weight, poisonStrength ); } ///////////////////////////////////////////////////////////////////////////////// // accessors (getters/setters) public void setPoisonStrength ( double d ) { poisonStrength = d; } public double getPoisonStrength () { return poisonStrength; } }