diff --git "a/\346\226\271\347\220\274/20220517-php\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232.md" "b/\346\226\271\347\220\274/20220517-php\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232.md" new file mode 100644 index 0000000000000000000000000000000000000000..20c8fa502444b6cc9d3ebc45756847a0bd6ee13e --- /dev/null +++ "b/\346\226\271\347\220\274/20220517-php\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232.md" @@ -0,0 +1,74 @@ +```php +brand=$brand; + $this->price=$price; + } + function run(){ + echo "这辆车的牌子是:".$this->brand.",它的价格为:",$this->price; + } + +/** + + * @return mixed + */ + public function getBrand() + { + return $this->brand; + } + +/** + + * @param mixed $brand + */ + public function setBrand($brand) + { + $this->brand = $brand; + } + +/** + + * @return mixed + */ + public function getPrice() + { + return $this->price; + } + +/** + + * @param mixed $price + */ + public function setPrice($price) + { + $this->price = $price; + } + + +} +$cc =new Car("本田","五万元"); +$cc->run(); +echo "
"; +//2、 在上例的基础上为汽车类定义一个子类——跑车类。为子类实例化对象并访问父类的属性。 + +class runCar extends Car{ + function __construct($brand, $price) + { + parent::__construct($brand, $price); + } + function spe(){ + echo "这辆跑车的牌子是:".$this->getBrand().",它的价格为:".$this->getPrice(); + } +} +$pc= new runCar("大众","十万元"); +$pc->spe(); +echo "
"; + +//3、 定义一个类,分别定义3个公共的属性和方法,3个受保护的属性和方法,3个私有属性和方法。 +``` +