diff --git "a/\346\235\250\351\221\253\344\273\252/20220517-php\345\257\271\350\261\241.md" "b/\346\235\250\351\221\253\344\273\252/20220517-php\345\257\271\350\261\241.md" new file mode 100644 index 0000000000000000000000000000000000000000..c545089e4350d7be9d20e62a8378e961e756453d --- /dev/null +++ "b/\346\235\250\351\221\253\344\273\252/20220517-php\345\257\271\350\261\241.md" @@ -0,0 +1,106 @@ +```php +kind=$kind; + $this->price=$price; +} +} +$a =new car("宝马","30万"); +echo "这辆车是:".$a->kind.",它的价格是:".$a->price; +echo "
"; +//2、 在上例的基础上为汽车类定义一个子类——跑车类。为子类实例化对象并访问父类的属性。 +class roadster extends car{//跑车 +var $speed; +function __construct($kind,$price,$speed){ + $this->kind=$kind; + $this->price=$price; + $this->speed=$speed; +} + +} +$b =new roadster("劳斯莱斯","120万","140"); +echo "这辆车的品牌为:".$b->kind.",价格为:".$b->price.",速度".$b->speed; +echo "
"; +//3、 定义一个类,分别定义3个公共的属性和方法,3个受保护的属性和方法,3个私有属性和方法。 +class cat{ + public $name; + public $kind; + public $color; + public function eat(){ + echo "它会吃饭"; + } + public function sleep(){ + echo "它会睡觉"; + } + public function run(){ + echo "它会跑"; + } + + private $weight; + private $tall; + private $sex; + /** + * @return mixed + */ + public function getWeight() + { + return $this->weight; + } + + /** + * @param mixed $weight + */ + public function setWeight($weight): void + { + $this->weight = $weight; + } + + /** + * @return mixed + */ + public function getTall() + { + return $this->tall; + } + + /** + * @param mixed $tall + */ + public function setTall($tall): void + { + $this->tall = $tall; + } + + /** + * @return mixed + */ + public function getSex() + { + return $this->sex; + } + + /** + * @param mixed $sex + */ + public function setSex($sex): void + { + $this->sex = $sex; + } + + private function climb{ + echo "会爬树"; + } + private function bite{ + echo "会咬人"; + } + private function drink{ + echo "会喝水"; + } + +} +``` +