From 57d3b1a62a1e35f4b8faa12eb4af24bf6212ac2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B2=91=E6=98=A5=E6=9F=B3?= <1553690980@qq.com> Date: Tue, 17 May 2022 22:30:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...HP\347\261\273\344\275\234\344\270\232.md" | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 "\345\262\221\346\230\245\346\237\263/2000.5.17-PHP\347\261\273\344\275\234\344\270\232.md" diff --git "a/\345\262\221\346\230\245\346\237\263/2000.5.17-PHP\347\261\273\344\275\234\344\270\232.md" "b/\345\262\221\346\230\245\346\237\263/2000.5.17-PHP\347\261\273\344\275\234\344\270\232.md" new file mode 100644 index 0000000..a2c9f50 --- /dev/null +++ "b/\345\262\221\346\230\245\346\237\263/2000.5.17-PHP\347\261\273\344\275\234\344\270\232.md" @@ -0,0 +1,91 @@ +```php +//1、写一段代码,定义一个汽车类,有品牌与价格两种属性。并为类实例化对象,为对象的属性赋值并引用。 +price=$price; + $this->brand = $brand; + } + function show(){ + echo "这辆车是". $this->brand."的牌子,"."价格为".$this->price; + } + /** + * @return mixed + */ + public function getBrand() + { + return $this->brand; + } + + /** + * @param mixed $brand + */ + public function setBrand($brand): void + { + $this->brand = $brand; + } + + /** + * @param mixed $price + * @return car + */ + public function setPrice($price) + { + $this->price = $price; + return $this; + } + + /** + * @return mixed + */ + public function getPrice() + { + return $this->price; + } +} +$car = new car("科迈罗",2000000); +echo $a->show(); + +``` + +```php +//2、在上例的基础上为汽车类定义一个子类——跑车类。为子类实例化对象并访问父类的属性。 +