Blogger Information
Blog 60
fans 1
comment 1
visits 64263
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
PHP面向对象编程:类的继承与final使用
PHP学习
Original
1184 people have browsed it

final class Dad

{

public function __construct()

{

echo "Dad init...";

}

public function A()

{

echo "Dad A...";

}

}

class Bay extends Dad

{

public function __construct()

{

parent::__construct();

echo "Bay init...";

}

public function B()

{

echo "Bay B...":

}

}

$bay = new Bay();

$bay->B();

final:此关键词是不希望子类继承父类,可以使用这个关键词;

extends:子类继承父类的方法

parent::__construct():子类继承父类的方法;

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