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

<?php
/**
* 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 ',男性有胡子<br>';
}

}
class Woman extends Person{

public function desc(){
echo ',女生喜欢购物<br>';
}
}

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

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

 

posted on 2017-07-13 18:32  程序猿?  阅读(134)  评论(0编辑  收藏  举报

导航