类的封装,公开,私有,继承

原创 2019-04-30 16:22:54 351
摘要:<?phpclass Staff{ public $name; protected $dept; private $salary; public function __construct($name,$dept,$salary) { $this->name = $name; $this->dept = $dept; $this->salary = $salary; }

<?php

class Staff

{


public $name;


protected $dept;



private $salary;



public function __construct($name,$dept,$salary)

{

$this->name = $name;

$this->dept = $dept;

$this->salary = $salary;


}



public function getDept()

{

return $this->dept;

}

}



$staff = new Staff('小龙女','开发部门','5000');


echo '姓名',$staff->name,'<br>';

echo '部门',$staff->getDept();


批改老师:查无此人批改时间:2019-05-05 09:53:11
老师总结:完成的不错。把php类这章课学完,就相当于入门了。继续加油。

发布手记

热门词条