From 4c13e66e975a70495a47a0bea652a5d1ad611fa5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=81=E8=A3=95?= <895585435@qq.com> Date: Tue, 17 May 2022 21:06:23 +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 --- ...42\345\220\221\345\257\271\350\261\241.md" | 179 ++++++++++++++++++ 1 file changed, 179 insertions(+) create mode 100644 "\346\242\201\350\243\225/20220517-php\351\235\242\345\220\221\345\257\271\350\261\241.md" diff --git "a/\346\242\201\350\243\225/20220517-php\351\235\242\345\220\221\345\257\271\350\261\241.md" "b/\346\242\201\350\243\225/20220517-php\351\235\242\345\220\221\345\257\271\350\261\241.md" new file mode 100644 index 0000000..7085ef8 --- /dev/null +++ "b/\346\242\201\350\243\225/20220517-php\351\235\242\345\220\221\345\257\271\350\261\241.md" @@ -0,0 +1,179 @@ +```php +brand=$brand; + $this->money=$money; +} + +function che(){ + echo $this->money."的".$this->brand; +} + +/** + + * @return mixed + */ + public function getMoney() + { + return $this->money; + } + +/** + + * @param mixed $money + */ + public function setMoney($money): void + { + $this->money = $money; + } + +/** + + * @return mixed + */ + public function getBrand() + { + return $this->brand; + } + +/** + + * @param mixed $brand + */ + public function setBrand($brand): void + { + $this->brand = $brand; + } + +} +$a = new Car("法拉利","100w"); +$a->che(); + +echo "
"; + +//2、 在上例的基础上为汽车类定义一个子类——跑车类。为子类实例化对象并访问父类的属性。 +class pc extends Car{ + function __construct($brand, $money) + { + parent::__construct($brand, $money); + } + function run(){ + echo parent::getBrand()."跑得很快!它要".parent::getMoney(); + } +} +$b=new pc("奥迪",400000); +$b->run(); + +//3、 定义一个类,分别定义3个公共的属性和方法,3个受保护的属性和方法,3个私有属性和方法。 +class lei{ + public $p; + public $o; + public $k; + public function v(){ + } + public function b(){ + } + public function n(){ + +} +protected $r; +protected $d; +protected $t; +protected function f(){ + +} +protected function g(){ + +} +protected function s(){ + +} + +private $h; +private $j; +private $i; +/** + + * @return mixed + */ + public function getH() + { + return $this->h; + } + +/** + + * @param mixed $h + */ + public function setH($h): void + { + $this->h = $h; + } + +/** + + * @return mixed + */ + public function getJ() + { + return $this->j; + } + +/** + + * @param mixed $j + */ + public function setJ($j): void + { + $this->j = $j; + } + +/** + + * @return mixed + */ + public function getI() + { + return $this->i; + } + +/** + + * @param mixed $i + */ + public function setI($i): void + { + $this->i = $i; + } + +private function h(){ + +} +private function j(){ + +} +private function i(){ + +} + + + +} +``` + -- Gitee