<?PHP
/*
Polymorphism in PHP5 is a technique where the function to be called is detected based on the class object calling it at runtime. The basis of Polymorphism is Inheritance and function overridden.
*/
class BaseClass
{
public function myMethod()
{
echo "BaseClass method called";
}
}
class DerivedClass extends BaseClass
{
public function myMethod()
{
echo "DerivedClass method called";
}
}
function processClass(BaseClass $c)
{
$c->myMethod();
}
$c = new DerivedClass();
processClass($c);
?>
/*
Polymorphism in PHP5 is a technique where the function to be called is detected based on the class object calling it at runtime. The basis of Polymorphism is Inheritance and function overridden.
*/
class BaseClass
{
public function myMethod()
{
echo "BaseClass method called";
}
}
class DerivedClass extends BaseClass
{
public function myMethod()
{
echo "DerivedClass method called";
}
}
function processClass(BaseClass $c)
{
$c->myMethod();
}
$c = new DerivedClass();
processClass($c);
?>
No comments:
Post a Comment