重写父类中的成员属性
2015-10-11 09:43
232 查看
<?php
//重写父类中的成员属性
//天气基类
class WeatherBase{
protected $country="中国";
protected $city="广州市";
protected $temperature=16;
protected $weather;
}
?>
<?php
class sonWeather extends WeatherBase{
public function Forecast(){
$this->country="北京";
$this->temperature=3;
$this->weather="多云";
//返回数组
return array(
"title"=>"天气预报",
"city"=>$this->country,
"temperature"=>$this->temperature,
"weather"=>$this->weather,
);
}
}
//调用
$class=new sonWeather();
$rows=$class->Forecast();
//输出数组数据
var_dump($rows);
//
// 输出:
//array (size=4)
// 'title' => string '天气预报' (length=8)
// 'city' => string '北京' (length=4)
// 'temperature' => int 3
// 'weather' => string '多云' (length=4)
?>
//重写父类中的成员属性
//天气基类
class WeatherBase{
protected $country="中国";
protected $city="广州市";
protected $temperature=16;
protected $weather;
}
?>
<?php
class sonWeather extends WeatherBase{
public function Forecast(){
$this->country="北京";
$this->temperature=3;
$this->weather="多云";
//返回数组
return array(
"title"=>"天气预报",
"city"=>$this->country,
"temperature"=>$this->temperature,
"weather"=>$this->weather,
);
}
}
//调用
$class=new sonWeather();
$rows=$class->Forecast();
//输出数组数据
var_dump($rows);
//
// 输出:
//array (size=4)
// 'title' => string '天气预报' (length=8)
// 'city' => string '北京' (length=4)
// 'temperature' => int 3
// 'weather' => string '多云' (length=4)
?>
相关文章推荐
- 黑马程序员----Java的异常处理机制
- 英语语法 完成式的过去时间
- 在ubuntu10.10 修改mysql data的默认路径后mysql服务启动失败
- android 常见分辨率(mdpi、hdpi 、xhdpi、xxhdpi )及屏幕适配注意事项
- 内连接、左外连接、右外连接、交叉连接区别
- Ubuntu 14.04.1 LTS上编译安装新的kernel
- 类方法的使用
- C++结构体内存对齐小结
- Javascript Array Reduce 用法解读
- 欢迎使用CSDN-markdown编辑器
- C#如何获得 WINDOWS 版本号
- Java SE 基础复习-内存泄露
- Java基础知识强化之IO流笔记39:字符流缓冲流之复制文本文件案例01
- UVa120
- eclipse运行web项目的保存位置
- cocos2dx 3.x 实现 A星(A*)(A-star)算法自动寻路(一)
- TCP/IP,HTTP,Socket的区别
- 黑马程序员-----object 类和包装类
- 串的模式匹配算法
- leetcode之H-index II