abstract://类成员的访问限制 class School { public $name; protected $stu; private $stuFile; public&nb
//类成员的访问限制 class School { public $name; protected $stu; private $stuFile; public function __construct($name,$stu,$stuFile) { $this->name = $name; $this->stu = $stu; $this->stuFile = $stuFile; } //创建一个接口,接收访问权限 public function getStu() { $res = $this->stu; if($this->name == '蒙古学院'){ $res = '你该不会叛变了吧。'; } return $res; } //创建一个接口,接收访问权限 public function getStuFile() { $res = $this->stuFile; if($this->name == '蒙古学院'){ $res = '准备反宋'; } return $res; }
//自动加载器 spl_autoload_register(function ($className){ require 'public/'.$className.'.php'; }); //实例化 $school = new School('南宋学院','张三','抗蒙班'); echo $school->name."<br>"; echo $school->getStu()."<br>"; echo $school->getStuFile()."<br>"; echo "<hr>"; $school = new School('蒙古学院','张三','抗蒙班'); echo $school->name."<br>"; echo $school->getStu()."<br>"; echo $school->getStuFile()."<br>";
Correcting teacher:韦小宝Correction time:2018-11-20 15:11:47
Teacher's summary:写的很不错!封装好了还可以反复调用!这种情况在实际的开发中是非常常用的哦!