diff --git "a/20220517-php\346\226\271\346\263\225.md" "b/20220517-php\346\226\271\346\263\225.md" new file mode 100644 index 0000000000000000000000000000000000000000..bf446bbd3af3a6fd48e58f75aba0bd47623900a9 --- /dev/null +++ "b/20220517-php\346\226\271\346\263\225.md" @@ -0,0 +1,176 @@ +```php +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 Car("大众","39999"); +$a->show(); + +echo "
"; +//2、在上例的基础上为汽车类定义一个子类——跑车类。为子类实例化对象并访问父类的属性。 + +class SportsCar extends Car { + + function __construct($brand, $price) + { + parent::__construct($brand, $price); + } + + function cool(){ + echo "它看来非常的酷"; + } + +} + +$b = new Sportscar("劳斯莱斯","9000000"); +echo "这辆汽车的牌子是:".$this->brand."它的价格为:".$this->price; +$b->cool(); +echo "
"; +/3、定义一个类,分别定义3个公共的属性和方法,3个受保护的属性和方法,3个私有属性和方法。 +class A{ + +//公共的 +public $name; +public $age; +public $sex; + function eat(){ + echo "吃饭"; + } + + function sleep(){ + echo "睡觉"; + } + + function skill(){//技能 + echo "手撕鬼子"; + } +//受保护的 +protected $height;//身高 +protected $weight;//体重 +protected $address;//地址 + protected function face(){ + echo "人脸识别"; + } + protected function short(){ + echo "验证码"; + } + protected function information(){ + echo "填写身份证信息"; + } + +//私有的 +private $grade;//成绩 +private $classname;//班级 +private $id;//学号 + /** + * @return mixed + */ + public function getGrade() + { + return $this->grade; + } + + /** + * @param mixed $grade + */ + public function setGrade($grade): void + { + $this->grade = $grade; + } + + /** + * @return mixed + */ + public function getClassname() + { + return $this->classname; + } + + /** + * @param mixed $classname + */ + public function setClassnamel($classname): void + { + $this->classname = $classname; + } + + /** + * @return mixed + */ + public function getId() + { + return $this->id; + } + + /** + * @param mixed $id + */ + public function setId($id): void + { + $this->id = $id; + } + + private function money{ + echo "会花钱"; + } + private function book{ + echo "会看书"; + } + private function attendclass{ + echo "会上专业课"; + } + +} + +``` + + +