PHP public, protected, private three types of access control mode differences, Protectedprivate
PHP public, protected, private three types of access control mode differences
Public: Common Type
The public method or property can be called through
PHP public, protected, private three types of access control mode differencesPublic: Common TypeThe public method or property can be called through Self::var in a subclass, Parent::method calling the parent class methodA method or property in an
Transferred from: http://www.cnblogs.com/webapplee/p/3771708.htmlJava modifier type (public,protected,private,friendly)Public classes, generic variables and methods, and any class within and outside the package can be accessed;Protected classes,
Access control over properties or methods is implemented by adding the public, protected, or private keywords to the front. It is defined as a public class member that can be accessed anywhere. A protected class member can be accessed by itself, its
0. IntroductionJava's access indicator, public,protected,private, can be used to decorate classes and methods by default.1. The scope is as followsPublic: Other classes can access this class or methodProtected: For inheritance, subclasses can access
PHP public, protected, private three types of access control mode differences
Public: Common Type在子类中可以通过self::var调用public方法或属性,parent::method调用父类方法在实例中可以能过$obj->var 来调用 public类型的方法或属性
Protected: Protected
java modifier symbol type:The most restrictive modifier in the Public:java language, commonly referred to as "public". The classes, properties, and methods that are decorated are not only accessible across classes, but also across packages (package).
problemJava modifier: public,protected,private, without modifiers. What difference does it have?Essence AnswerAs shown in the following table, y means access (visibility), n means no access, for example, 3rd y of the first row, the variable/method
Difference between protected private and public, protectedprivate
1. public, protected, and private are used to define the access permissions of members in Java. Another type is "default", that is, no permission modifier is added before a member.
Analysis of Java decoration appended public default protected private static final abstractthe function of a modifier: used to define a class, method, or variable, usually at the front end of a statementTwo classification (broadly divided into two
There are three properties for functions and class variables in the PHP class: Public protected private, when to use what attributes are good entanglements, deliberately found an instance, so that looks clearer.Public represents the global, and the
PHP public, protected, private three types of access control mode differencesPublic: Common TypeThe public method or property can be called through Self::var in a subclass, Parent::method calling the parent class methodA method or property in an
for the public inheritance method:(1) The public member of the parent class becomes the public member of the subclass, allowing code outside the class to access those members ;(2) The private member of the parent class is still the private member of
Java scope public protected private, and the difference when not writing, publicprotected
Below I will draw a simple table to illustrate the problem:
Modifiers
Scope (visible)
Current class
Same package
Child
In PHP, the access control of the property or method is implemented in front of the public private protected and other keywords, public decorated class members can be accessed anywhere, private decorated class members can only be accessed by
Public is the most accessible, such as name, everyone can know someone else's name, this is not a secretProtected has lower access rights, only subclasses can access the protected property of the parent class. It's like Lao Tzu's property is
Java supports four different kinds of access rights:
modifier
Description
Public
Common, visible to all classes.
Protected
Protected, visible to classes and all subclasses within the same
Encapsulation is one of the three characteristics of surface object programming, encapsulation is to combine the properties and services of an object into a separate unit, and to conceal the inner details of the object as much as possible, including
Analyze the public, protected, private, and default access permissions of java from the perspective of instances, publicprotected
1. public
Same package
1. Internal
Public class A {public int f = 1; public void m1 () {} public void m2 () {f = 2;
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.