Blogger Information
Blog 250
fans 3
comment 0
visits 321718
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
OOP 对象中私有属性继承
梁凯达的博客
Original
609 people have browsed it

实例

<?php

	class A{
		public $money = 100;
		private $age = 18;
	}

	//子类可以继承父类中的所有内容但是私有的东西不能继承
	class B extends A{
		public  function say(){
			//访问自己的属性 但是父类的私有属性是不可见的所以我们依然访问不了
			return $this->age;
		}
	}

	$p = new B;
	echo $p->money;
	//私有的属性 继承后无法访问 等同于不存在
	//echo $p->age;
	//var_dump() 是调试级别代码 什么都可以打印出来
	var_dump($p);	
	//echo $p->say();

运行实例 »

点击 "运行实例" 按钮查看在线实例

 

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