php学习:parent关键字的使用

<?php
header("Content-Type:text/html;charset=UTF-8");


class Person{

    public $userName='我是老爸';
    public $age='58';

    protected function play(){

        echo '老爸,需要有人陪着打麻将!';

    }

}


class Student extends Person{
    public $userName='我是学生';
    public $age='16';

    public function play(){
        parent::play();
        echo '学生不能打麻将!';

    }
    
}



$xiaoming = new Student();
$xiaoming->play();   //老爸,需要有人陪着打麻将!学生不能打麻将!


?>

猜你喜欢

转载自blog.csdn.net/qq_32584661/article/details/80520499