<?php
// Define an abstract class 'Animal'
abstract class Animal {
protected $name;
public function __construct($name) {
$this->name = $name;
}
// Define an abstract method 'speak'
abstract public function speak();
}
// Define a class 'Cat' that extends 'Animal'
class Cat extends Animal {
public function speak() {
return "Meow";
}
}
// Define a class 'Dog' that extends 'Animal'
class Dog extends Animal {
public function speak() {
return "Woof";
}
}
// Create objects of the classes and call their 'speak' methods
$cat = new Cat("Fluffy");
$dog = new Dog("Buddy");
echo $cat->speak() . "<br>"; // Output: Meow
echo $dog->speak(); // Output: Woof
?>