[ACCEPTED]-What is the difference between access specifiers and access modifiers?-access-specifier
"access modifier" is the official 5 term for private
, protected
and public
used in the Java language specification. "access 4 specifier" is used synonymously in 3 the Java API doc, but this is the first time I've noticed 2 that. It's probably better to stick with 1 the JLS term.
Referring to the Sun Java Docs they both 1 seem to be the same:
Access Modifier
- Search for
access specifier
on this page.
The term Access specifier used by c++ programmers not in 4 java. In java Officially we use Access Modifier.
For example: when 3 we declare a class with private, static 2 the compiler clearly shows the error message 1 as follows:
Java has basically 2 types of Modifiers:
- java access modifiers
- java non-access modifiers
Java 2 access modifiers and Java access specifiers 1 are the same thing, which are public
, private
, protected
.
In some older languages public, private, protected 13 and default like C++ are considered as access 12 specifiers and everything else is considered 11 as access modifier but in Java there is 10 no terminology for specifier, everything 9 is by default considered as modifier only. So 8 public, private, protected, default, final, abstract, static, strictfp, synchronized, native, transient 7 and volatile are all modifiers only.
Simple 6 test for it is when we compile the following 5 code
private class Test{ }
we will get compile 4 time error saying that modifier private 3 not allowed here. This is true for other 2 modifiers also. Maybe java compiler (javac) sees 1 everything as a "modifier" only.
There is nothing known as "Access specifiers" in java, there are only Access modifiers in java
The misconception is from languages like 6 C++ where public, private, protected, default 5 are considered as Access specifiers and 4 remaining (static, final, etc) are considered 3 as access modifiers
Following is the proof 2 as compiler says "modifier private 1 not allowed here" i.e. compiler said modifier and not specifier
According to me, yes, both terms refer to 1 the same thing and are used interchangeably.
That JDI reference is the only place I have 6 ever seen the term 'access specifier' used 5 in a Java specification. Even there, public/protected/private/package 4 are also called 'modifiers'. There's really 3 no reason to ever use the term 'access specifier' in 2 Java, it is clearly just a mistake on one 1 page out of many thousands.
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.