php面向对象继承的初步使用

2021-06-23 07:06

阅读:464

标签:int   extend   class   tor   struct   nbsp   对象   ons   bsp   

/**
* Created by PhpStorm.
* User: fu
* Date: 2017/7/13
* Time: 13:34
*/

class Person{

public $name;
public $age;

public function __construct($name, $age)
{
$this->name = $name;
$this->age = $age;
}

public function desc(){

}
public function introduce(){
echo ‘姓名:‘.$this->name.‘,年龄:‘.$this->age;
$this->desc();
}
}

class Man extends Person{

public function desc(){
echo ‘,男性有胡子
‘;
}

}
class Woman extends Person{

public function desc(){
echo ‘,女生喜欢购物
‘;
}
}

$person = new Man(‘李四‘, 25);
$person->introduce();

$person = new Woman(‘丽丽‘, 28);
$person->introduce();

 

php面向对象继承的初步使用

标签:int   extend   class   tor   struct   nbsp   对象   ons   bsp   

原文地址:http://www.cnblogs.com/zxy945/p/7162053.html


评论


亲,登录后才可以留言!