From 13e3c78044595ba3a9362b9b3d8fd2b931b8a67e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E6=B5=B7=E6=B6=8C=E2=80=9Dgit=20push=20git=20con?= =?UTF-8?q?fig=20--global=20user=2Eemail=203480707803=40qq=2Ecom=20git=20c?= =?UTF-8?q?onfig=20--global=20user=2Ename=20=E5=90=B4=E6=B5=B7=E6=B6=8C?= =?UTF-8?q?=E2=80=9D?= <3480707803@qq.com> Date: Tue, 17 May 2022 23:47:12 +0800 Subject: [PATCH] text --- ...4 \345\217\212\344\275\234\344\270\232.md" | 0 ...75\350\275\246\344\275\234\344\270\232.md" | 173 ++++++++++++++++++ 2 files changed, 173 insertions(+) rename "\345\220\264\346\265\267\346\266\214/200220516PHP\345\207\275\346\225\260\347\273\204 \345\217\212\344\275\234\344\270\232.md" => "\345\220\264\346\265\267\346\266\214/20220516PHP\345\207\275\346\225\260\347\273\204 \345\217\212\344\275\234\344\270\232.md" (100%) create mode 100644 "\345\220\264\346\265\267\346\266\214/20220517-php\346\261\275\350\275\246\344\275\234\344\270\232.md" diff --git "a/\345\220\264\346\265\267\346\266\214/200220516PHP\345\207\275\346\225\260\347\273\204 \345\217\212\344\275\234\344\270\232.md" "b/\345\220\264\346\265\267\346\266\214/20220516PHP\345\207\275\346\225\260\347\273\204 \345\217\212\344\275\234\344\270\232.md" similarity index 100% rename from "\345\220\264\346\265\267\346\266\214/200220516PHP\345\207\275\346\225\260\347\273\204 \345\217\212\344\275\234\344\270\232.md" rename to "\345\220\264\346\265\267\346\266\214/20220516PHP\345\207\275\346\225\260\347\273\204 \345\217\212\344\275\234\344\270\232.md" diff --git "a/\345\220\264\346\265\267\346\266\214/20220517-php\346\261\275\350\275\246\344\275\234\344\270\232.md" "b/\345\220\264\346\265\267\346\266\214/20220517-php\346\261\275\350\275\246\344\275\234\344\270\232.md" new file mode 100644 index 0000000..174080d --- /dev/null +++ "b/\345\220\264\346\265\267\346\266\214/20220517-php\346\261\275\350\275\246\344\275\234\344\270\232.md" @@ -0,0 +1,173 @@ +### 作业 + +```php + +//1、 写一段代码,定义个汽车类,有品牌与价格两种属性。并为类实例化对象,为对象的属性赋值并引用。 +class Dom +{ +private $name;//品牌 +private $money;//价格 + + function __construct($name, $money) + { + $this->name=$name; + $this->money=$money; + } +function sum(){ + echo $this->name." "."价格是".$this->money; +} + /** + * @return mixed + */ + public function getName() + { + return $this->name; + } + + /** + * @param mixed $name + */ + public function setName($name): void + { + $this->name = $name; + } + + /** + * @return mixed + */ + public function getMoney() + { + return $this->money; + } + + /** + * @param mixed $money + */ + public function setMoney($money): void + { + $this->money = $money; + } + +} +$a=new Dom("凯迪拉克",2999999); +$a->sum(); +//2、 在上例的基础上为汽车类定义一个子类——跑车类。为子类实例化对象并访问父类的属性。 +class pao extends Dom { + function __construct($name, $money) + { + parent::__construct($name, $money); + } + function sports(){ + echo $this->getName()." "."价格是".$this->getMoney(); + } + +} +$b = new pao("法拉利",3000000); +echo "
"; +$b->sports(); +//3、 定义一个类,分别定义3个公共的属性和方法,3个受保护的属性和方法,3个私有属性和方法。 +class shu +{ + //3个公共的属性和方法 + public $a1; + public $a2; + public $a3; + + function name1() + { + echo "我叫" . $this->a1; + } + + function age1() + { + echo "我" . $this->a2 . "岁了"; + } + + function love1() + { + echo "我的爱好是" . $this->a3; + } + +//3个受保护的属性和方法 + protected $b1; + protected $b2; + protected $b3; + protected function name2() + { + + } + + protected function age2() + { + echo "我" . $this->a2 . "岁了"; + } + + protected function love2() + { + echo "我的爱好是" . $this->a3; + } + +//3个私有属性和方法 + private $c1; + private $c2; + private $c3; + private function name3() + { + + } + + private function age3() + { + + } + + private function love3() + { + } + /** + * @return mixed + */ + public function getC1() + { + return $this->c1; + } + + /** + * @param mixed $c1 + */ + public function setC1($c1): void + { + $this->c1 = $c1; + } + /** + * @return mixed + */ + public function getC2() + { + return $this->c2; + } + + /** + * @param mixed $c2 + */ + public function setC2($c2): void + { + $this->c2 = $c2; + } + /** + * @return mixed + */ + public function getC3() + { + return $this->c3; + } + + /** + * @param mixed $c3 + */ + public function setC3($c3): void + { + $this->c3 = $c3; + } +``` + -- Gitee