diff --git "a/\346\235\216\347\221\236\351\230\263/20220517-php\351\235\242\345\220\221\345\257\271\350\261\241.md" "b/\346\235\216\347\221\236\351\230\263/20220517-php\351\235\242\345\220\221\345\257\271\350\261\241.md" new file mode 100644 index 0000000000000000000000000000000000000000..94e34fe814f29f4b6f065fcdab08526afa27629d --- /dev/null +++ "b/\346\235\216\347\221\236\351\230\263/20220517-php\351\235\242\345\220\221\345\257\271\350\261\241.md" @@ -0,0 +1,144 @@ +```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("兰博基尼",9999999); +$a->show(); + +class sportscar extends car{ + function __construct($brand, $price) + { + parent::__construct($brand, $price); + } + + function run() + { + echo "名为".parent::getBrand()."的跑车,它车速超越所有车辆,这台超跑的价格为".parent::getPrice(); + } + + +} +$b=new sportscar("迈凯伦",1000000000); +$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(){ + + } +} +``` +