这样?
<meta charset="utf-8">
<?php
class Auto{
public $color="";
public $tires=4;
function __construct( $color, $tires ) {
$this->color = $color;
$this->tires = $tires;
}
function __tostring(){
return "颜色:".$this->color."<br/>轮胎数量:".$this->tires;
}
}
class Bus extends Auto{
public $ride;
function __construct( $color, $tires,$ride ) {
$this->color = $color;
$this->tires = $tires;
$this->ride=$ride;
}
function __tostring(){
return "颜色:".$this->color."<br/>轮胎数量:".$this->tires."<br/>共载人数:".$this->ride;
}
}
$a=new Auto("红色","4");
echo $a;
echo "<hr>";
$b=new Bus("白色",8,40);
echo $b;
?>
帮助到你能点个采纳吗,谢谢~~
您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~
如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~
ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632