public 表示全局,类内部外部子类都可以访问;private表示私有的,只有本类内部可以使用;protected表示受保护的,只有本类或子类或父类中可以访问;
<?
//父类
class father{
public function a(){
echo "function a";
}
private function b(){
echo "function b";
}
protected function c(){
echo "function c";
}
}
//子类
class child extends father{
function d(){
parent::a();//调用父类的a方法
}
function e(){
parent::c(); //调用父类的c方法
}
function f(){
parent::b(); //调用父类的b方法
}
}
$father=new father();
$father->a();
$father->b(); //显示错误 外部无法调用私有的方法 Call to protected method father::b()
$father->c(); //显示错误 外部无法调用受保护的方法Call to private method father::c()
$chlid=new child();
$chlid->d();
$chlid->e();
$chlid->f();//显示错误 无法调用父类private的方法 Call to private method father::b()
?>
分享到:
相关推荐
Use these lists to help locate a class that contains the functionality you are interested in.Visual C++ Programmer's Guide explains how to use the class library to program for Microsoft Windows NT®,...
- **User-Defined Functions:** Description of how to create and use custom functions in PHP. - **Function Parameters:** Explanation of function parameters, including default values, passing by ...
How can we use a class Foo in a header file without access to its definition? We can declare data members of type Foo* or Foo&. We can declare (but not define) functions with arguments, and/or ...
### Effective C#: Key Insights and Best Practices #### Introduction "Effective C#" is an invaluable resource for developers ...- **Pattern:** Events allow objects to notify other objects of changes in...
your program to use IMAP instead of POP and expect everything in IMAP to be supported. Assuming your mail server supports IMAP, your JavaMail-based program can take Fundamentals of the JavaMail API...
Access control modifiers play a crucial role in managing how class members can be accessed. Public members can be accessed from anywhere, providing an interface for interacting with the object. ...
How to Use To see how a StoriesProgressView can be added to your xml layouts, check the sample project. Overview public class YourActivity extends AppCompatActivity implements StoriesProgressView....
private static final boolean USE_CACHE = false; private static final int DEFAULT_OFFSCREEN_PAGES = 1; private static final int MAX_SETTLE_DURATION = 600; // ms private static final int PAGER_NEXT...
In Dbf.Net you don't have to write any code, if you don't want to wait for the garbage collector to collect your individual you can call SaveChanges. Dbf.Net ADO.Net Collapse Copy Codevoid ...
ICS V8 is the current development release which is held in a public Version Control repository that is zipped each night for easy download. The download page above also includes the OpenSSL binaries ...
.How to use *********** It's very easy to use it once you know the when the attacks apply.So here are the explanations: 1.Common Modulus Attack: not really an attack but more of a tool, its ...
- **Access Modifiers**: Understanding how to use `public`, `protected`, `private`, and package-private (default) modifiers to control access to classes, methods, and fields. - **Encapsulation**: The ...
这份【Java试题(60道)】涵盖了Java编程的核心内容,结合【How to use eclipse.txt】,可以帮助学习者不仅提升理论知识,还能熟练运用Eclipse这一主流的Java开发工具。通过系统地解答这些题目,可以有效地巩固Java...
2、作用域public,private,protected,以及不写时的区别? 8 3、String 是最基本的数据类型吗? 8 4、float 型float f=3.4是否正确? 8 5、语句float f=1.3;编译能否通过? 8 6、short s1 = 1; s1 = s1 + 1;有什么错? 8...