cnq 发表于 2017-3-25 08:01:48

php面向对象--继承

<?php
class Person {
protected $name;
public function __construct($name) {
$this->name = $name;
}
public function showPersonInfo() {
echo "person name: " . $this->name;
}
}
class Developer extends Person{
protected $macType;
public function __construct($name,$macType) {
parent::__construct($name);
$this->macType = $macType;
}
public function showPersonInfo() {
echo "developer name:" . $this->name . " developer's mac type:" . $this->macType;
}
}

$developer = new Developer("goodboy","MBP");
$developer->showPersonInfo();
?>
 
页: [1]
查看完整版本: php面向对象--继承