abstract:class Student{ public $name; public $age; protected $sex; private $score; const XUEJI = '20180808'; public function __construct($name,$age,$sex,$score){ $this ->name = $name; $this -&g
class Student
{
public $name;
public $age;
protected $sex;
private $score;
const XUEJI = '20180808';
public function __construct($name,$age,$sex,$score){
$this ->name = $name;
$this ->age = $age;
$this ->sex = $sex;
$this ->score = $score;
}
public function getSex(){
switch($this ->sex){
case 1:
$sex = '男';
break;
case 2:
$sex = '女';
break;
default;
$sex = '保密';
}
return $sex;
}
public function getScore(){
$f = $this -> score;
if($f >= 80){
$score = "优";
}else if($f < 80 && $f >=60){
$score = "良";
}else{
$score = "差";
}
return $score;
}
}
$stu = new Student('李二狗','18','1','59');
echo '姓名:'.$stu->name.' 年龄:'.$stu -> age.' 性别:'.$stu ->getSex().' 班级:'.Student::XUEJI." 成绩:".$stu -> getScore();