First, the access range of the private, public, and protected access labels.
PRIVATE: It can only be accessed by 1. functions in this class, 2. Other functions. Cannot be accessed by any other user, nor can the object of this class be
(1) for the public modifier, it has the most access rights and can access any class, interface, exception, etc. under Classpath. It is often used for external situations, i.e. the form of an interface to an object or class outside.(2) for the
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
Differences among public, protected, and private in C ++: protectedprivate
1. Access scope of private, public, and protected:
Private: It can only be accessed by functions in the class and their meta-functions. It cannot be accessed by any other
[Thinking in Java] modifier public, protected, default, private, thinkingprotected
When using Java, four modifiers, public, protected, default (no modifier), and private, are often encountered. The differences between them are written here.
Public:
There are four access modifiers in Java: public,protected,default,privateNote: This is about access to the properties and methods in the class, not the access rights of the class1.default: Package access rightsIf nothing is written, default defaults.
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
1, private modifier, that the members are private, only their own can access;2, protected, represents the protected permission, embodied in the inheritance, that is, the subclass can access the parent class protected members (subclasses can access
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).
Let me simply draw a table to illustrate the problem:
modifiers
Scope (visible)
Current class
Same package
Descendant class
Other Packages
Public
√
√
√
√
Draw conclusions from Classname::functionnmae (), instantiation, parent, self
Classname::functionnmae () requires a static method (public mode)
Parent::functionnmae () parent class needs to be static method (public, protected two
: This article mainly introduces the differences between public, protected, and private. For more information about PHP tutorials, see. Use className: functionNmae (), instantiation, parent, and self to draw a conclusion.
ClassName: functionNmae ()
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
When using Java, often encounter four kinds of modifiers, namely public,protected, default (no modifier), private, here write down their differences public: In-Package outside the package accessProtected: In-package access, out-of-package only
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
PublicHas the maximum access rights. all classes are accessible. Protectedis primarily used to protect subclasses. itself, subclasses, and classes in the same package can accessDefaultWithout modifiers. Sometimes referred to as friendly, it is
A variable in a C + + class that has the following keyword as the modifier.
1. Public: Access is available anywhere in the program.
2 Protected: Only the class itself and its derived classes and their friend functions, the friend class can access.
The following question is taken from a forum post:
Three classes O, P, and q are known. Class O defines a private method F1, a public method F2, and a protected method F3: class P and class Q are derived classes of Class O. The Inheritance Method is
(5) package-related
Class: Use the class keyword to create a new class.For example:Class aclassname{Class body goes here}The words modifying class include public, abstract, and final. abstract and final cannot simultaneously modify class. Internal
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.