php中重写理解_PHP教程

WBOY
Release: 2016-07-13 10:17:17
Original
1061 people have browsed it

php中重写理解

我们经常听到面向对象的三大特性:封装、继承、多态,但是还有许多特性,那么我们是否记得重写呢?在学习的时候简单的记录了下php中等重写方法:

1)先通过例子看下,这样更加明了


//定义父类(也可以称为基类)
class Goods {
public $goods_name = 'Goods:name';

public function sayName() {
echo $this->goods_name;
}

}
//定义子类(也可以成为扩展类)
class Book extends Goods {
public $goods_name='Book:name';
public function sayName() {
echo 'run in book';
}
}
//实例化对象
$b1 = new Book;

//输出run in book,因为子类重写了父类的sayName()方法
$b1->sayName();

下章总结下php中的重写调用...

www.bkjia.com true http://www.bkjia.com/PHPjc/894186.html TechArticle php中重写理解 我们经常听到面向对象的三大特性:封装、继承、多态,但是还有许多特性,那么我们是否记得重写呢?在学习的时候简单的...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!