Blogger Information
Blog 28
fans 0
comment 0
visits 16907
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
11月29日作业:PHP抽象类和PHP接口
SmileHoHo
Original
537 people have browsed it

PHP抽象类和PHP接口

1.抽象类

  1. <?php
  2. abstract class a{
  3. public $name;
  4. public function __construct($name){
  5. $this -> name = $name;
  6. }
  7. public function af(){
  8. echo $this -> name;
  9. }
  10. abstract public function aff();
  11. }
  12. class b extends a{
  13. public function aff(){
  14. echo $this -> name;
  15. }
  16. }
  17. $a = new b('欧阳');
  18. $a -> af();
  19. echo '<br>';
  20. $a = aff();

2.接口类

  1. <?php
  2. abstract class P{
  3. protected $name;
  4. protected function __construct($name='peter'){
  5. $this->name;
  6. }
  7. public function getName(){
  8. return $this->name;
  9. }
  10. abstract protected function setName($value);
  11. }
  12. class stu extends P{
  13. public function __construct($name = 'peter'){
  14. parent::__construct($name);
  15. }
  16. public function setName($value){
  17. $this->value;
  18. }
  19. }
  20. $stu = new stu('猪');
  21. echo '真的很贵哦:' . $stu->getName() . '<hr>';
  22. $stu->setName('灭绝师太');
  23. echo '讲师' . $stu->getName();

手抄书:





Correcting teacher:查无此人查无此人

Correction status:qualified

Teacher's comments:完成的不错,继续加油。
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments