Week 3 Monday Lecture - Animal Example source code The abstract class Animal is meant to be subclassed by actual Animal objects(such as cats and

Week 3 Monday Lecture - Animal Example source code The...

This preview shows page 1 - 3 out of 5 pages.

Animal Example source code /** * The abstract class Animal is meant to be subclassed by * actual Animal objects (such as cats and dogs...) * * @author kclowes * @version 1.0 (Jan 21, 2008) */ public abstract class Animal { private String name; /** Constructor for a named Animal. * * @param name the Animal's name (null is OK) */ public Animal(String name) { this.name = name; } /** * Get the Animal's name. * @return its name */ public String getName() { return name; } /** * Set the Animal's name. * @param name the Animal's name */ public void setName(String name) { this.name = name; } /** * Get a String representation of the Animal's noise. * @return its noise */ public abstract String noise(); /** * Get a String representation of an Animal. * The format is: * <pre> * AnimalName + " is a " * </pre> * @return Animal as a String */ @Override public String toString() { return name + " is a "; }
Image of page 1
} /** * A Dog is a friendly domesticated Animal. A Dog has a name * and can be either big or small. Big and small dogs * make different noises. * @author kclowes * @version 1.0 (Jan 21, 2008) */ public class Dog extends Animal { private int size;//1 means small; 2 means big; others illegal /** * Construct a Dog with the specified name and size.
Image of page 2
Image of page 3

You've reached the end of your free preview.

Want to read all 5 pages?

  • Fall '15
  • OLIVIADAS
  • The Animals, public String toString, public Zoo

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture