From 890fd0d3ed29b65ce97fc755466517bf43808adc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E5=90=AF=E6=98=8C?= <3110587048@qq.com> Date: Tue, 17 May 2022 19:43:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...73\344\270\216\345\257\271\350\261\241.md" | 147 ++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 "\345\220\264\345\220\257\346\230\214/20220517-PHP\347\261\273\344\270\216\345\257\271\350\261\241.md" diff --git "a/\345\220\264\345\220\257\346\230\214/20220517-PHP\347\261\273\344\270\216\345\257\271\350\261\241.md" "b/\345\220\264\345\220\257\346\230\214/20220517-PHP\347\261\273\344\270\216\345\257\271\350\261\241.md" new file mode 100644 index 0000000..80a5c6b --- /dev/null +++ "b/\345\220\264\345\220\257\346\230\214/20220517-PHP\347\261\273\344\270\216\345\257\271\350\261\241.md" @@ -0,0 +1,147 @@ +# 解答 + +``` php +brand = $brand; + $this->price = $price; + } + + /** + * @return mixed + */ + public function getBrand() + { + return $this->brand; + } + + /** + * @param mixed $brand + */ + public function setBrand($brand) + { + $this->brand = $brand; + } + /** + * @return mixed + */ + public function getPrice() + { + return $this->price; + } + /** + * @param mixed $price + */ + public function setPrice($price) + { + $this->price = $price; + } + +} +$cars=new car("车名:"."法拉利 ","车的价格:"."500万元"); +echo $cars->getBrand().$cars->getPrice(); + +//echo $a; +//2、 在上例的基础上为汽车类定义一个子类——跑车类。为子类实例化对象并访问父类的属性。 +class bus extends car{ + private $color;//颜色 + private $speed;// 速度 + + function __construct($brand, $price,$color,$speed) + { + $this->color = $color; + $this->speed = $speed; + parent::__construct($brand, $price); + } + + /** + * @return mixed + */ + public function getColor() + { + return $this->color; + } + + /** + * @param mixed $color + */ + public function setColor($color) + { + $this->color = $color; + } + + /** + * @return mixed + */ + public function getSpeed() + { + return $this->speed; + } + + /** + * @param mixed $speed + */ + public function setSpeed($speed) + { + $this->speed = $speed; + } +} + +echo "

"; +$buses=new bus("车名:".'劳斯莱斯 ',"车的价格:"." ".'1千万元 ',"车的颜色:"." ".'蓝色 ',"车的速度:"." ".'1000米每秒'); + +echo $buses->getBrand().$buses->getPrice().$buses->getColor().$buses->getSpeed(); + + +//3、 定义一个类,分别定义3个公共的属性和方法,3个受保护的属性和方法,3个私有属性和方法。 +class Qu +{ public $eat; + public $fiy; + public $day; + public function ii(){//公共 + + } + public function rt(){ + + } + public function tw(){ + + } + protected $ing; + protected $zng; + protected $ong; + protected function aa(){//保护 + + } + protected function qw(){ + + } + protected function zx(){ + + } + private $name; + private $age; + private $breed; + private function s(){ // 私有 + + } + private function cv(){ + + } + private function op(){ + + } +} +``` + -- Gitee