<?php
class Person{
public $name;
public function __construct($name="" ){
$this->name=$name;
}
public function say(){
echo "我叫".$this->name ;
}
}
?>
<?php
class Student extends Person{
public $name;
public function __construct($name=""){
$this->name =$name;
}
//这里定义了一个和父类中同名的方法,将父类中的说话方法覆盖并重写
public function say(){
echo "我叫".$this->name .",今年25岁了" ;
}
}
?>
<?php
class Student extends Person{
public $name;
public $age;
public function __construct($name="",$age=25){
$this->name =$name;
$this->age =$age;
}
public function say(){
echo "我叫".$this->name .",今年".$this->age."岁了" ;
}
}
?>
<?php
class Student extends Person{
public $name;
public $age;
public function __construct($name="",$age=25){
parent::__construct($name,$age);
$this->age =$age;
}
public function say(){
parent::say();
echo ",今年".$this->age."岁了" ;
}
}
?>