package inheritAnimals; // Dogs inherit everything Pets have, but also add things // a Dog is-a Pet public class Dog extends Pet { // in addition to variables inherited from Pet private String breed; // constructors are not inherited, always have to write public Dog() { // super() happens automatically super.name = "Spot"; // same as name = "spot" this.breed = "mutt"; // same as breed = "mutt" } public Dog(String name, int age, String breed) { // can't call this() because both this() and super() require first line // call superclass parameterized constructor explicitly super(name, age); setBreed(breed); } // in addition to methods inherited from Pet public String getBreed() { return breed; } public void setBreed(String breedval) { if (breedval != null) { this.breed = breedval; } } // overriding toString @Override public String toString() { // use the toString method we are overriding in this method return super.toString() + " a " + getBreed(); } }