/* VampireBat.java example code AC Chapin */ package MonsterInherit; /** * class representing a Vampire Bat **/ public class VampireBat extends Monster { /** * default constructor for VampireBat **/ public VampireBat() { super(); // call Monster constructor teeth = 2; // can only do if protected in Monster alive = false; } /** * copy constructor for VampireBat **/ public VampireBat(VampireBat original) { super(original); // call Monster copy constructor // nothing else to set up in this class } /** * vampirebats eat by sucking blood * overrides eat from Monster **/ public void eat() { System.out.println("I vant to suck your bluuud."); } /** * vampirebats can fly **/ public void fly() { System.out.println("Up above the world I fly, like a gothy teatray in the sky."); } /** * fake clone method * **/ public VampireBat clone() { return new VampireBat(this); } /** * overrides toString from Monster * while also using it * @return * string representing this VampireBat **/ public String toString() { return "vampire bat " + name; } /** * check if equal to obj * */ public boolean equals(Object obj) { // only other VampireBats if (obj != null && obj instanceof VampireBat) { // no new instance vars, so no cast needed return super.equals(obj); } return false; } }