接口类与接口实战(号码判断抽象类与继承)
实例
<?php namespace _1009; abstract class phone { protected $number; public function __construct($number='15021518604'){ $this->number=$number; } public function getNumber(){ return $this->number; } abstract public function setNumber($num); } class Type extends phone{ //构造方法不会继承 public function __construct($number){ parent::__construct($number); } public function setNumber($num){ return $this->number=$num; } } $typ=new Type('15021518604'); echo '手机号码:'.$typ->getNumber().'<br>'; $typ->setNumber('021-58583295'); echo '座机号:'.$typ->getNumber().'<br>';
运行实例 »
点击 "运行实例" 按钮查看在线实例