diff --git "a/\351\231\210\346\242\201\346\235\260/20220517-PHP\351\235\242\345\220\221\345\257\271\350\261\241.md" "b/\351\231\210\346\242\201\346\235\260/20220517-PHP\351\235\242\345\220\221\345\257\271\350\261\241.md" new file mode 100644 index 0000000000000000000000000000000000000000..044f7cc674d935f8632172c602e10ec3765687f2 --- /dev/null +++ "b/\351\231\210\346\242\201\346\235\260/20220517-PHP\351\235\242\345\220\221\345\257\271\350\261\241.md" @@ -0,0 +1,120 @@ +```php+HTML +brand=$brand; + $this->price=$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; + } + + function show(){ + echo "一辆".$this->brand."价格为".$this->price; + } + +} + +$a=new Vehicle("奔驰","50万"); +$a->show(); + +echo "\n"; + + +//2、在上例的基础上为汽车类定义一个子类——跑车类。为子类实例化对象并访问父类的属性。 + +class Sportscar extends Vehicle { + + function __construct($brand, $price) + { + parent::__construct($brand, $price); + } + + function Speed(){ + echo "速度很快"; + } + + + +} + +$a = new Sportscar("法拉利","200万"); +$a->show(); +$a->Speed(); + + +//3、定义一个类,分别定义3个公共的属性和方法,3个受保护的属性和方法,3个私有属性和方法。 +class A{ + +//公共的 +public $a; +public $b; +public $c; +//受保护的 +protected $d; +protected $e; +protected $f; + +//私有的 +private $h; +private $g; +private $k; + +public function a(){} +public function b(){} +public function c(){} + +protected function d(){} +protected function e(){} +protected function f(){} + +private function h(){} +private function g(){} +private function k(){} + + + + + + +} + + +``` +