php学习:方法的继承

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

//面向对象的特点:继承、封装、多态

class Person{

    public $userName;
    public $age;

    public function eat(){

        echo '人都要吃饭!';

    }

}
//继承:extends(php是单继承,只能继承一个)
class Student extends Person{

}


$XiaoMing = new Student();
$XiaoMing->eat();    //人都要吃饭!


?>

猜你喜欢

转载自blog.csdn.net/qq_32584661/article/details/80520436
今日推荐