Blogger Information
Blog 15
fans 0
comment 0
visits 7772
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
1. 请实例演绎你对面向对象类与对象关系的理解? 2. 请实例演绎oop的封装性是怎么实现的? 3. 请实例演绎构造函数的作用有哪些?
ッ小眼睛っ
Original
466 people have browsed it
  1. <?php
  2. class people {
  3. public $name;// 姓名
  4. public $gender; //性别
  5. protected $age; //年龄
  6. private $birthday; //生日
  7. public function __construct($name,$gender,$age,$birthday)
  8. {
  9. $this->name = $name;
  10. $this->gender = $gender;
  11. $this->age = $age;
  12. $this->birthday = $birthday;
  13. }
  14. public function say()
  15. {
  16. return "大家好我是{$this->name},我是一个{$this->gender}孩 <br>";
  17. }
  18. public function speak(){
  19. return "我今年{$this->age}岁 我的生日是{$this->birthday}";
  20. }
  21. }
  22. $obj = new people('小明','男',13,'2008.05.06');
  23. echo $obj->say();
  24. echo $obj->speak();
  25. $obj->name='小红';
  26. $obj->gender ='女';
  27. echo $obj->say();
  28. echo $obj->speak();
Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post