From db1460ee471354762bedb50dc060adf8fe26619e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E4=BD=B3=E4=B8=BD?= <2898669424@qq.com> Date: Tue, 17 May 2022 17:22:36 +0800 Subject: [PATCH] dd --- ...42\345\203\217\345\257\271\350\261\241.md" | 149 ++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 "\345\210\230\344\275\263\344\270\275/20220517-\351\235\242\345\203\217\345\257\271\350\261\241.md" diff --git "a/\345\210\230\344\275\263\344\270\275/20220517-\351\235\242\345\203\217\345\257\271\350\261\241.md" "b/\345\210\230\344\275\263\344\270\275/20220517-\351\235\242\345\203\217\345\257\271\350\261\241.md" new file mode 100644 index 0000000..3caed4d --- /dev/null +++ "b/\345\210\230\344\275\263\344\270\275/20220517-\351\235\242\345\203\217\345\257\271\350\261\241.md" @@ -0,0 +1,149 @@ +# 作业 + +```php +brand=$brand; + $this->price=$price; + } + 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; + } + +} +$a=new car("大众",10); +$a->show(); + +//子类 +class sportscar extends car{ + function __construct($brand, $price) + { + parent::__construct($brand, $price); + } + + function run() + { + echo "名为".parent::getBrand()."的车车,价格为".parent::getPrice(); + } + + +} +$b=new sportscar("本田",100); +$b->run(); + + +//3、 定义一个类,分别定义3个公共的属性和方法,3个受保护的属性和方法,3个私有属性和方法。 +class lei{ + var $a; + var $b; + var $c; + protected $d; + protected $e; + protected $f; + private $g; + private $h; + private $i; + /** + * @return mixed + */public function getG() +{ + return $this->g; +}/** + * @param mixed $g + */public function setG($g): void +{ + $this->g = $g; +}/** + * @return mixed + */public function getH() +{ + return $this->h; +}/** + * @param mixed $h + */public function setH($h): void +{ + $this->h = $h; +}/** + * @return mixed + */public function getI() +{ + return $this->i; +}/** + * @param mixed $i + */public function setI($i): void +{ + $this->i = $i; +} + function a(){ + + } + function b(){ + + } + function c(){ + + } + protected function d(){ + + } + protected function e(){ + + } + protected function f(){ + + } + private function g(){ + + } + private function h(){ + + } + private function i(){ + + } +} +``` \ No newline at end of file -- Gitee