Difference between access specifier and access mod

2019-01-24 16:15发布

问题:

I've read around on the internet and I've heard people say

Access specifiers ::

The access specifier determines how accessible the field is to code in other classes. Access ranges from totally accessible to totally inaccessible. You can optionally declare a field with an access specifier keyword: public, private, or protected.

Access Modifiers ::

You can optionally declare a field with a modifier keyword: final or volatile and/or static and/or transient, abstract, etc.

Is there any difference at all? Because most definitions for access modifiers and access specifiers state the same thing.. which seems so ambiguous.

回答1:

In this context, you can think of access specifiers as protection specifiers -- they specify where a variable can be accessed from. By contrast, access modifiers are completely different; they specify how variables should (or should not) be accessed; e.g. read-only, volatile, etc.

i.e., a variable can be public but read-only, or it can be private and writable -- the access specifiers have nothing to do with the modifiers.

However, I'm a little surprised that the terminology is for C#, since Microsoft actually calls public and private "access modifiers", and it calls volatile and readonly just plain "modifiers".



回答2:

As far as I can see, there is no difference at all between the terms. The MS C++ documentation for example uses both terms for the same thing.



回答3:

Refer from MSDN C# 4.0 document, I think you misunderstand something. C# does not has some word like "access specifier" but it call modifiers or access modifiers for modifiers that use to control access level.

Hope this help.

Update

I think, this question like you ask me that what difference between package and namespace is. It depends on what language or professor that you use or believe. Nothing is wrong on same kind like this question.

From experience (and the meaning of words), access modifier should mean about controlling access like public or private. In the other hand, Access Specifiers should be the super class of access modifier that mean it include other keyword like static, final, readonly or something like that in it.

PS. Both C#, VB.NET and Java, they use access modifier for keyword like public or private. In the other hand, C++ use access specifier for the same keyword.

Modifiers (C# 4.0)

Access Levels in Visual Basic (VB.NET 2010)

Controlling Access to Members of a Class (Java)

Access Specifiers (C++ 2010)



回答4:

I believe an access specifier determines the visibility for a certain field / method.

An access modifier tells you more about the behavior and use of that field. You can say whether or not the field requires an instantiated object or if it can be overriden.



回答5:

Access specifiers of a class indicates what other class variables can access in the present class. Access modifiers of a class indicates the same functionality of access specifiers