Polymorphism in php
Implementing the polymorphism principle can be done in either of two ways, i.e., either choosing abstract classes or interfaces.
/* Program to demonstrate a polymorphism principle in php */
<?php
class A
{
function disp()
{
echo "display method of class A";
}
}
class B extends A // Class B inherits functions and methods of Class A
{
function disp()
{
echo "display method of class B";
}
}
$obj = new B();
$obj ->disp();
?>
Output: display method of class B
0 Comment(s)