/* Cat.java example code AC Chapin */ package ObjectsEx; package Classes; // a cat -- example of a class public class Cat { // INSTANCE VARIABLES public String catname; public boolean hungry; // METHODS // make a noise public void miaow() { /* here we use the name variable for whatever Cat we called the method for so if we called mrWhiskers.miaow() then we will use mrWhiskers.name */ System.out.println("Miaow! I'm " + catname); } // eat a Bunny public void eat(Bunny food) { System.out.println(catname + " is eating " + food.name + ". YUM!"); hungry = false; food.name = "Ex-Bunny"; } // toString method creates String representing the Cat @Override public String toString() { // booleans show up as "true" or "false" so you have to think about how to structure the text return "it is " + hungry + " that " + catname + " the cat is hungry"; } }