function play() { // Call the Pet::play() method: parent::play(); echo "<p>$this->name is fetching.</p>"; }
/** *echo "dog's name" is fetching */ function play() { parent::play(); //echo Satchel is playing echo "<p>{$this->name} is fetching. </p>"; //echo Satchel is fetching. }
/** * Increase a pet's happiness level. * * Increases the pet's happiness level and destroys the item. * * @param Pet $pet * @param integer $quantity * @return string The success message. **/ public function playWith(Pet $pet, $quantity) { if ($quantity > $this->getQuantity()) { throw new ArgumentError("This stack does not have {$quantity} items."); } $pet->play($this->getHappinessBonus() * $quantity); $this->updateQuantity($this->getQuantity() - $quantity); return "{$pet->getPetName()} is happier now."; }
/** * echo "cat's name" is climbing */ function play() { parent::play(); echo "<p>{$this->name} is climbing</p>"; }
{ function play() { echo "<p>{$this->name} is fetching.</p>"; } } // End of Dog class. # ***** END OF CLASSES ***** # // Create a dog: $dog = new Dog('Satchel'); // Create a cat: $cat = new Cat('Bucky'); // Create an unknown type of pet: $pet = new Pet('Rob'); // Feed them: $dog->eat(); $cat->eat(); $pet->eat(); // Nap time: $dog->sleep(); $cat->sleep(); $pet->sleep(); // Have them play: $dog->play(); $cat->play(); $pet->play(); // Delete the objects: unset($dog, $cat, $pet); ?> </body> </html>