From 46f997ff54c85abb693bf157d4f65d699edcdd41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B6=E6=80=9D=E6=80=9D?= <3242902095@qq.com> Date: Tue, 17 May 2022 22:27:30 +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\345\222\214\346\226\271\346\263\225.md" | 167 ++++++++++++++++++ 1 file changed, 167 insertions(+) create mode 100644 "\345\217\266\346\200\235\346\200\235/20220517-\347\261\273\345\222\214\346\226\271\346\263\225.md" diff --git "a/\345\217\266\346\200\235\346\200\235/20220517-\347\261\273\345\222\214\346\226\271\346\263\225.md" "b/\345\217\266\346\200\235\346\200\235/20220517-\347\261\273\345\222\214\346\226\271\346\263\225.md" new file mode 100644 index 0000000..de28fc1 --- /dev/null +++ "b/\345\217\266\346\200\235\346\200\235/20220517-\347\261\273\345\222\214\346\226\271\346\263\225.md" @@ -0,0 +1,167 @@ +# 练习 + +```php +//1、写一段代码,定义一个汽车类,有品牌与价格两种属性。并为类实例化对象,为对象的属性赋值并引用。 +brand=$brand; + $this->price=$price; +} +function run(){ + echo "一辆".$this->price."元的".$this->brand; +} + + /** + * @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; + } + +} +$car=new Car("法拉利",99999999); +$car->run(); +``` + +```php +//2、在上例的基础上为汽车类定义一个子类——跑车类。为子类实例化对象并访问父类的属性。 +running(); +``` + +```php +//3、定义一个类,分别定义3个公共的属性和方法,3个受保护的属性和方法,3个私有属性和方法。 +characters; + } + + /** + * @param mixed $characters + */ + public function setCharacter($characters): void + { + $this->character = $characters; + } + + /** + * @return mixed + */ + public function getWeight() + { + return $this->weight; + } + + /** + * @param mixed $weight + */ + public function setWeight($weight): void + { + $this->weight = $weight; + } + + /** + * @return mixed + */ + public function getHeight() + { + return $this->height; + } + + /** + * @param mixed $height + */ + public function setHeight($height): void + { + $this->height = $height; + } +``` + -- Gitee