Blogger Information
Blog 35
fans 3
comment 0
visits 25293
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
11月29日作业 抽象类 接口学习
随风
Original
529 people have browsed it

抽象类

`<?php
abstract class Demo{
protected $name;

  1. protected function __construct($name)
  2. {
  3. $this->name =$name;
  4. }
  5. public function getName(){
  6. return $this->name;
  7. }
  8. abstract protected function setName ($v);

}

class Stu extends Demo{

  1. public function __construct($name ){
  2. parent::__construct($name);
  3. }
  4. // 子类中必须实现抽象父类中的抽象方法
  5. public function setName($v){
  6. $this->name = $v;
  7. }

}

  1. $stu = new Stu('gzg');
  2. echo $stu->getName();
  3. $stu->setName('hyx');
  4. echo $stu->getName();

`

接口

`<?php

namespace admin;
interface iv{
public function setFuel($fuel);
public function setPurpose($pur);
}

class Car implements iv{
public $fuel;
public $pur;

  1. public function setFuel($fuel)
  2. {
  3. $this->fuel=$fuel;

}
public function setPurpose($pur)
{
// TODO: Implement setPurpose() method.
$this->pur=$pur;
}

  1. public function getInfo(){
  2. return $this->fuel . $this->pur . '车' ;
  3. }

}

$car = new Car();
$car -> setFuel(‘新能源’);
$car -> setPurpose(‘家用’);
echo $car ->getInfo();`

手抄


上次的作业写好

已在27日提交,如有可能请在课堂上把这个例子的 添加和修改也将一下。这样就能吃透这一块了。

总结

还能理解,但是比较吃力,请尽量用实战场景把这些知识点进行连接一下,这样印象更深,也能更好的理解。

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
Author's latest blog post