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 0000000000000000000000000000000000000000..de28fc1984cb5b13ddfb675c338b2715bab33fb6 --- /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; + } +``` +