From 8872d1a19868429408b250eb9f87c2b4d4305c0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=BE=E9=9D=92=E5=87=A4?= <2658978250@qq.com> Date: Tue, 17 May 2022 21:08:54 +0800 Subject: [PATCH] tijiao --- ...42\345\220\221\345\257\271\350\261\241.md" | 114 ++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 "\346\233\276\351\235\222\345\207\244/20220517-PHP\351\235\242\345\220\221\345\257\271\350\261\241.md" diff --git "a/\346\233\276\351\235\222\345\207\244/20220517-PHP\351\235\242\345\220\221\345\257\271\350\261\241.md" "b/\346\233\276\351\235\222\345\207\244/20220517-PHP\351\235\242\345\220\221\345\257\271\350\261\241.md" new file mode 100644 index 0000000..45c428a --- /dev/null +++ "b/\346\233\276\351\235\222\345\207\244/20220517-PHP\351\235\242\345\220\221\345\257\271\350\261\241.md" @@ -0,0 +1,114 @@ +1. 写一段代码,定义一个汽车类,有品牌与价格两种属性。并为类实例化对象,为对象的属性赋值并引用。 + + ```php + class Car + { + private $brand;//品牌 + private $price;//价格 + + function __construct($brand,$price){ + $this->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; + } + function show(){ + echo "这是价格为".$this->price."的".$this->brand; + } + } + + $car =new Car("宝马",5000000); + $car->show(); + echo "