欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

php 继承_PHP教程

程序员文章站 2024-01-10 10:47:10
...

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 使弱类型语言,没有重...
相关标签: php 继承