131-PHP子类可以访问父类public修饰的类成员

<?php
    class father{        //定义father类
        public function cook(){
            return '烹饪';
        }
    }
    class son extends father{        //定义son类
        public function programme(){        //定义儿子类的programme成员方法
            return '编程';
        }
    }
    $son=new son();        //实例化son类的一个对象
    //访问儿子对象的成员方法
    echo '儿子会'.$son->cook().'和'.$son->programme();
?>

猜你喜欢

转载自www.cnblogs.com/tianpan2019/p/11013973.html
今日推荐