In Java:
The access permissions in Java include public, private, protected, and default package access permissions. If the attribute methods in the class do not show the specified access permission, the package access permission is granted, I like
Summary:Within a class, its members (including member variables and member methods) can be interviewed by other classes, depending on the modifier of that member, and whether a class can be visited by other classes depends on the class's modifiers.
1. Protected access control characters can be used for methods and member variables.
2. Methods and member variables declared as protected can be accessed by all classes in the same package, just like the default modifier package.
3. Can be accessed
Why cannot private and protected be used for classes and interfaces? Private, protected, default, and privateprotected cannot be used for interface methods.
For java programmers, the differences and usage of the access permission modifiers public,
In Java, the three reserved words are used to modify the data members and member functions of the class, and the class itself. In C ++, the data members and member functions of the modifier class, and the inheritance of the class, but you don't need
In fact, this is simply a saying: "A subclass that is not in the same package as the base class can only access protected members inherited from the base class, you cannot access the protected members of the base-class instance ".
Original works
Protectedto talk about the protected access rights issue. Look at example 1 below:Test.java
Class MyObject {} public
class Test {public
static void Main (string[] args) {
MyObject obj = new MyObject (); C5/>obj.clone (); Compile
Protected modified static properties and methods call Way 1: Direct class name invocation2: Instantiation of the parent class object for invocation3: Instantiating a subclass object for invocationProtected modified non-static properties and Methods
2017-11-04 22:28:39
Permission to access the permission modifier
Access modifier protected Permissions Understanding
In core Java there is a phrase " in the object class, the Clone method is declared as protected, so
1. The protected access controller can be used for methods and member variables.2. The methods and member variables declared as protected can be accessed by all classes in the same package, just like the default modifier package.3. The sub-class can
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.