Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between access specifier and access modifier

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.

like image 246
Robin Maben Avatar asked Feb 17 '11 07:02

Robin Maben


People also ask

What is the difference between access modifiers and non access modifiers in Java?

The public keyword is an access modifier, meaning that it is used to set the access level for classes, attributes, methods and constructors. We divide modifiers into two groups: Access Modifiers - controls the access level. Non-Access Modifiers - do not control access level, but provides other functionality.

What are different access specifiers differentiate between all of them?

In C++, there are three access specifiers: public - members are accessible from outside the class. private - members cannot be accessed (or viewed) from outside the class. protected - members cannot be accessed from outside the class, however, they can be accessed in inherited classes.

What are the 4 access modifiers?

Access modifiers are keywords that can be used to control the visibility of fields, methods, and constructors in a class. The four access modifiers in Java are public, protected, default, and private.

What are access specifiers and access modifiers in C++?

The access modifiers of C++ are public, private, and protected. One of the main features of object-oriented programming languages such as C++ is data hiding. Data hiding refers to restricting access to data members of a class. This is to prevent other functions and classes from tampering with the class data.

What is called access specifier?

Public Access Specifiers. C++ access specifiers are used for determining or setting the boundary for the availability of class members (data members and member functions) beyond that class. For example, the class members are grouped into sections, private protected and public .

What is an access specifier in Java?

Java provides entities called “Access Modifiers or access specifiers” that help us to restrict the scope or visibility of a package, class, constructor, methods, variables, or other data members. These access modifiers are also called “Visibility Specifiers”.


1 Answers

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".

like image 128
user541686 Avatar answered Sep 18 '22 10:09

user541686