算是一个大的php编程题吧,没办法,求帮助
有为鱼
有为鱼 2019-01-08 15:02:44
0
3
956

定义一个父类Person(人),包含xm(姓名)、xb(性别)两个属性成员和一个构造函数,xm、xb在主程序中不能直接读写,在构造函数中完成姓名、性别的初始化。

定义一个子类teacher(教师)继承自Person,包含属性gh(工号)和构造函数,在主程序也不能直接读写gh,用构造函数可以实现所有数据成员的初始化,并在子类中定义一个方法,用来输出全部教师信息,定义一个析构函数显示“再见”。

现有一个教师“李四”、性别“男”、工号 123,请用此数据初始化,并输出


有为鱼
有为鱼

Antworte allen(2)
Miss等待

<?php


class Person

{

protected $xm;

protected $xb;


function __construct()

{

$this->xm = '李四';

$this->xb = '男';

}


}


class Teacher extends Person

{

protected $gh;


function __construct()

{

$this->gh = 123;

$this->xm = '李四';

$this->xb = '男';

}


public function message()

{

return "姓名是: {$this->xm} 性别是 :{$this->xb} 工号是:{$this->gh}";

}


function __destruct()

{

// return '再见!';

echo '再见!';

}


}


$teacher = new Teacher();

echo $teacher->message();


空城

你倒是贴出来呀,这样说的把我都饶晕了

  • Antwort 我也是想有个人给我弄答案,要不是我也不会发这个帖子
    有为鱼 Autor 2019-01-09 15:01:44
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!