Home  >  Article  >  Backend Development  >  php基础~

php基础~

WBOY
WBOYOriginal
2016-06-13 10:16:40906browse

php基础求助~~~~
有个问题是关于继承和接口的?~~~~~~~

我有个class person implements ispeak{public function speak(){echo "人说话";}}类,
鸟类class bird implements ispeak{public function speak(){echo "鸟叫";}}类 
 接口ispeak{public function speak();}

我一个艺人类 yrPerson extends person {} 
因为艺人可以学鸟叫 我现在想让艺人也可以鸟叫 但不要重复写代码public function speak(){echo "鸟叫";}


高手给讲讲!!!!急呀 经理总说我代码重复率太高了~~~~~


------解决方案--------------------
忘了要继承person类,小改一下

PHP code
class yrPerson extends person{    //添加口技方法...    public function show($a){        $func=Factory::func($a);        return $func->speak();    }}$person=new yrPerson();$person->speak();        //自己说话$person->show('dog');    //学狗叫$person->show('bird');    //学鸟叫//接着学...<div class="clear">
                 
              
              
        
            </div>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn