/* 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("Vlad", 2, false); // call Monster constructor } /** * param constructor for VampireBat **/ public VampireBat(String name) { super(name, 2, 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."); } /** * clone method - gives us polymorphic way to call right copy constructor * **/ 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 instanceof VampireBat) { // no new instance vars, so no cast needed return super.equals(obj); } return false; } }