G

Untitled

public
Guest Apr 26, 2025 Never 51
Clone
Plaintext paste1.txt 29 lines (29 loc) | 704 Bytes
1
<?php
2
class Animal{
3
protected $name;
4
public function_Construct($name){
5
$this->name;
6
echo"an Animal named {$this->name} is created.<br>";
7
}
8
protected function getName(){
9
return $this->name;
10
}}
11
class dog extends Animal{
12
private $breed;
13
public function_Construct($name,$breed){
14
parent::_construct($name);
15
$this->breed=$breed;
16
echo"a dog of breed {$this->breed} is created.<br>";
17
}
18
public function speak() {
19
echo $this->getName().",the{$this->breed},barks.<br>";
20
}
21
public function showBreed(){
22
echo"breed:{$this->breed}<br>";
23
}}
24
$Animal=new Animal("lion");
25
$dog =new dog("buddy","golden Retriever");
26
$Animal->speak();
27
$dog->speak();
28
$dog->showBreed();
29
?>