134-PHP子类重写父类方法,并调用父类方法

<?php
    class father{        //定义father类
        public function method(){        //定义方法
            echo '<br />father method';
        }
    }
    class son extends father{        //定义继承自father类的son类
        public function method(){        //重写父类方法        
            echo 'son method';
        }
        public function parent_method(){        //定义方法
            parent::method();        //调用父类方法
        }
    }
    $son=new son();        //实例化son类的对象
    //调用son类的方法
    $son->method();
    $son->parent_method();
?>

不忘初心,如果您认为这篇文章有价值,认同作者的付出,可以微信二维码打赏任意金额给作者(微信号:382477247)哦,谢谢。

原文地址:https://www.cnblogs.com/tianpan2019/p/11013991.html