-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphpmethod.php
More file actions
33 lines (26 loc) · 776 Bytes
/
Copy pathphpmethod.php
File metadata and controls
33 lines (26 loc) · 776 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
class Animal {
public $name;
public $type;
public $sound;
public function __construct($name, $type, $sound) {
$this->name = $name;
$this->type = $type;
$this->sound = $sound;
}
public function makeSound() {
echo $this->name . " the " . $this->type . " makes a " . $this->sound . " sound.<br>";
}
}
class Dog extends Animal {
public function wagTail() {
echo $this->name . " the " . $this->type . " wags its tail happily.<br>";
}
}
// Create an instance of the Dog class
$myDog = new Dog("Jackie", "Dog", "barking");
// Use the makeSound method from the parent class
$myDog->makeSound();
// Use the wagTail method from the Dog class
$myDog->wagTail();
?>