当前位置:Gxlcms > PHP教程 > php继承_PHP教程

php继承_PHP教程

时间:2021-07-01 10:21:17 帮助过:19人阅读

php 继承


name=$name;
            $this->age=$age;
            $this->sex=$sex;
            $this->school = $school;
        }
         
        function study(){
            echo $this->age;
            echo $this->name.":我在{$this->school}学习
"; } /* 覆盖父类的say(),子类中重载的方法,不能低于父类中的访问权限(子类可以放大权限,但不能缩小权限) 父类中是public function say(){} 子类中变成了private function say(){} private function say(){ echo "{$this->name}:我在{$this->school}学习呢,请不要打扰我
"; } 这时候会报错Fatal error: Access level to Student::say() must be public (as in class Person */ public function say(){ parent::say(); echo "{$this->name}:我在{$this->school}学习呢,请不要打扰我
"; } } #$student = new Student; #$student->school="北京大学附属中学"; #$student->name="haha"; #$student->age=32; #$student->study(); #$student->say(); $student2 = new Student("李会东",24,"男","北京大学"); #echo $student2->school; $student2->say(); ?>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1061541.htmlTechArticlephp 继承 ?php/*继承性 1.面向对象的三大特性之一 2.开放性,可扩充性 3.增加代码的重用性 4.提高了软件的可维护性 php 使弱类型语言,没有重...

人气教程排行