protected修饰符修饰的成员在整个继承链上使用

protected修饰符修饰的成员在整个继承链上使用

php编程知识qingyu2020-10-28 14:14:021037A+A-

  protected修饰符修饰的成员在整个继承链上使用

  Protected可以在整个继承链上被访问

  示例代码:

class A()
{
	protected $num =10; 
	
}

class B extends A{
	public function getNum()
	{
		echo $this->$num;
	}
}
$b = new B;
$b->getNum();  //输出10
class A()
{
	public function getNum()
	{
		echo $this->$num;
	}
}

class B extends A{
	protected $num =10; 
}

$b = new B;
$b->getNum();  //输出10

protected修饰符修饰的成员在整个继承链上使用

点击这里复制本文地址 欢迎来到大黄鸡源码分享网
qrcode

大黄鸡源码编程网 © All Rights Reserved.  
网站备案号:闽ICP备18012015号-4
Powered by Z-BlogPHP
联系我们| 关于我们| 广告联系| 网站管理