定義一個(gè)父類別Person(人),包含xm(姓名)、xb(性別)兩個(gè)屬性成員和一個(gè)建構(gòu)函數(shù),xm、xb在主程式中不能直接讀寫,在建構(gòu)子中完成姓名、性別的初始化。
定義一個(gè)子類別teacher(教師)繼承自Person,包含屬性gh(工號)和建構(gòu)函數(shù),在主程式也不能直接讀寫gh,用建構(gòu)函數(shù)可以實(shí)現(xiàn)所有資料成員的初始化,並在子類別中定義一個(gè)方法,用來輸出全部教師訊息,定義一個(gè)析構(gòu)函數(shù)顯示「再見」。
現(xiàn)有一位教師「李四」、性別「男」、工號 123,請用此資料初始化,並輸出
<?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();
你倒是貼出來呀,這樣說的把我都饒暈了