評等結果
點擊便能為這篇文章進行評等!
[評等總次數: 0,平均評等: 0]
這篇介紹的是物件導向程式設計的最大重點,繼承 extends 也就是讓你少寫很多重覆的code的重點功能,廢話不多說直接看範例。
//extends 繼承 你可以想成遺傳 你爸爸有的一些特徵 在你的身上也會看到,但又沒有完全一樣(又不是複製人), 但你會的又比你的爸爸多
class People {
private $height;//身高
private $weight;//體重
private $sex;//姓別
function set_height($height1) { $this->height = $height1;}
function set_weight($weight1) {$this->weight = $weight1;}
function set_sex($sex1) {$this->sex = $sex1;}
function get_height() {return $this->height;}
function get_weight() {return $this->weight;}
function get_sex() {return $this->sex;}
}
class People2 extends People { //People2 繼承了 people 內所有的屬性跟方法
private $action;//動作
function set_action($action1) {$this->action = $action1;}
function get_action() {return $this->action;}
}
$jeff = new People2();
$jeff->set_height(170);
$jeff->set_weight(65);
$jeff->set_sex('male');
$jeff->set_action('sit');
echo 'jeff 的身高是:';
echo $jeff->get_height();
echo '<br>jeff 的體重是:';
echo $jeff->get_weight();
echo '<br>jeff 的姓別是:';
echo $jeff->get_sex();
echo '<br>jeff 的動作是:';
echo $jeff->get_action();
//顯示結果
/*
jeff 的身高是:170
jeff 的體重是:65
jeff 的姓別是:male
jeff 的動作是:sit
*/
評等結果
點擊便能為這篇文章進行評等!
[評等總次數: 0,平均評等: 0]
味丹 隨緣 鮮蔬百匯/素肉骨茶/素魷魚羹麵/韓式泡菜/麻辣燙湯麵 (5包/袋) 素食 全素 泡麵
義美e家小館-素食炒飯270g/包
水壺背袋 水壺網袋 水瓶袋 多色可選 戶外郊遊 登山野餐 可放手機 水壺背帶
手指伸縮狼爪 伸縮爪 機械爪 狼爪 伸縮爪子