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)哦,謝謝。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM