What do rabbits put in their computers? Hoppy disks.
/**
 * A DomesticAnimal "is-a" Animal -- this means that a DomesticAnimal has the behavior we described in Animal!
 */
/**
 * extends means we must write code for all of the methods 
 * we defined in Animal.  If we don't, we won't be able to create
 * a DomesticAnimal!
 */
public class DomesticAnimal extends Animal{ 
    
    /**
     * What additional state might a DomesticAnimal have?
     * In addition to the name, color, hungerLevel, and favoriteFood,
     * a DomesticAnimal has an owner and an address!
     */
    
    private String owner;
    private String address;
    
    /**
     * super refers to the constructor in the "parent" class --
     * this would be the constructor we made in Animal!
     * That constructor needs a color, name, and favoriteFood to
     * work properly, so we use super to send it the information
     * it needs to finish making a DomesticAnimal!
     */
    public DomesticAnimal(String color, String name, String favoriteFood, String owner, String address){
        super(color, name, favoriteFood);
        this.owner = owner;
        this.address = address;
    }
    
    
    /**
     * A DomesticAnimal already has all of the behavior defined in Animal.
     * Below is the additional behavior that a DomesticAnimal would have, but
     * wouldn't make sense for EVERY animal to have!
     */
    
    public void greetOwner(){
        System.out.println(getName() + " says hello to " + owner + "!");
    }
    
    
    public String getOwner(){
        return owner;
    }
    
    
    /**
     * What if a DomesticAnimal moves or changes owners?  We want to be able
     * to change this state.  To do so, we use "setters!"  This is a setter for
     * the owner.
     */
    public void setOwner(String newOwner){
        owner = newOwner;
    }
    
    
    public void goHome(){
        System.out.println(getName() + " is headed home to " + address + "!");
    }
    
    
    public String getAddress(){
        return address;
    }
    
    
    public void setAddress(String newAddress){
        address = newAddress;
    }
    
    
    /**
     * Because DomesticAnimal extends Animal, we must define the move() method if
     * we want to be able to create a DomesticAnimal.
     * extends means that a DomesticAnimal "is-a" Animal!
     */
    public void move(){
        System.out.println(getName() + " is walking!");
    }
    
}
                                 Level 1
                        Level 1 Level 2
                        Level 2 Level 3
                        Level 3 Level 4
                        Level 4 Level 5
                        Level 5 Level 6
                        Level 6 Level 7
                        Level 7 Glossary
                        Glossary 
                