PHP OOP之继承

本文概述

这是从另一类访问一个类的功能的概念。如果我们将类特征继承到另一个类中, 则可以访问这两个类属性。我们可以使用’extends’关键字来扩展类的功能。

  • 它支持层次分类的概念。
  • 继承具有三种类型, 单, 多和多级继承。
  • PHP仅支持单一继承, 其中只能从单个父类派生一个类。
  • 我们可以使用接口来模拟多重继承。

例子1

<?php
class a
	{
		function fun1()
		{
			echo "srcmini";
		}
	}
	class b extends a
	{
		function fun2()
		{
			echo "SSSIT";
		}
	}
	$obj= new b();
	$obj->fun1();
?>

输出

PHP OOP之继承

例子2

<?php
	class demo
	{
		public function display()
		{
			echo "example of inheritance  ";
		}	
	}
	class demo1 extends demo
	{
		public function view()
		{
			echo "in php";
		}	
	}
	$obj= new demo1();
	$obj->display();
	$obj->view();
?>

输出

PHP OOP之继承

来源:

https://www.srcmini02.com/29321.html

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_37970.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?