【php开源代码栏目提醒】:文章导读:在新的一年中,各位网友都进入紧张的学习或是工作阶段。网学会员整理了php开源代码-poly.php的相关内容供大家参考,祝大家在新的一年里工作和学习顺利!
<html>
<head>
<title>多态的应用</title>
</head>
<body>
<h2>多态的简单应用</h2>
<?php
class shap
{
function area($x)
{
return $x;
}
}
class rectangle extends shap
{
function area($x,$y)
{
return $x*$y;
}
}
class circle extends shap
{
function area($x)
{
return 3.14*$x*$x;
}
}
$a=new shap();
echo "图形的边长是:".$a->area("5")."<br>";
$c=new rectangle();
echo "矩形的面积是:".$c->area("3","5")."<br>";
$b=new circle();
echo "圆形的面积是:".$b->area("3")."<br>";
?>
</body>
</html>