Last active
May 22, 2023 22:16
-
-
Save kamrankr/8b7101fcf4d537a5c43c to your computer and use it in GitHub Desktop.
simplest Polymorphism example in Php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* simplest Polymorphism example in Php */ | |
abstract class Animal | |
{ | |
static function makeSound(Animal $animal) | |
{ | |
return $animal->getsound(); | |
} | |
} | |
class dog extends Animal | |
{ | |
function getsound() | |
{ | |
return "Woof Woof"; | |
} | |
} | |
class cat extends Animal | |
{ | |
function getsound() | |
{ | |
return "Meow Meow"; | |
} | |
} | |
echo Animal::makeSound(new cat); | |
echo Animal::makeSound(new dog); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment