コード例 #1
0
ファイル: 9.重载.php プロジェクト: sykinggg/sykinggg
	重载可以重写父类中指定方法所实现的功能
代码示例:
<?php 
class father
{
    //定义father 类
    public function printNUM()
    {
        echo 10;
    }
}
class child extends father
{
    //子类child 继承 father 类
    public function printNUM()
    {
        //重写 father 类中的方法,实现重载
        echo 10 * 10;
    }
}
$test1 = new father();
$test1->printNUM();
//输出10
echo "<br>";
$test2 = new child();
$test2->printNUM();
// 输出100
?>
运行结果:
10
100