通过继承实现多态(小学生日常)
2016-07-18 12:07
399 查看
<?php /** * Created by PhpStorm. * User: admin * Date: 2016/7/18 * Time: 9:41 */ //通过继承实现多态 class father{ public $name; public function getWeight(){ return"59kg"; } public function setName(){ $this->name="father";//this 调用本身 } } class son extends father{ public function setName() { // parent::setName(); // TODO: Change the autogenerated stub $this->name="son"; } } //上段注释,输出father。 class son1 extends father{ public function getWeight() { return parent::getWeight(); // TODO: Change the autogenerated stub } } $son=new son(); $son->setName(); echo $son->name."<br>"; $weight=new son1(); $weight->getWeight(); echo $weight->getWeight();
相关文章推荐
- 【杭电】[1865]1sting
- Java JVM:内存溢出(栈溢出,堆溢出,持久代溢出以及 nable to create native thread)
- codeforces 696C PLEASE 概率dp+公式递推+费马小定理
- Android中的基础----android:gravity和android:layout_gravity的使用原则和区别
- GP学习(七)—Accessing raster workspaces
- 通达OA列表控件添加js代码,实现js的获取和赋值
- Android AllView使用效果
- i3 i5 i7的区别
- Android Studio修改项目编译版本
- BestCoder 2nd Anniversary/HDU 5719 姿势
- 真机测试的时候出现 data parameter is nil
- .NET类库Newtonsoft.Json的各json与对之应的Model记录
- [从头读历史] 第307节 星球战争 BC2699 至 BC2600(公元前27世纪)
- java中的匿名内部类总结
- Linux的SOCKET编程详解
- Opencv图像识别从零到精通(9)----对比度亮度改变
- linux下如何查看系统和内核版本
- 2016Linux运维三期决心书
- 【杭电】[1715]大菲波数
- HDU 2063 过山车 最大二分匹配