What is the difference between access specifiers and access modifiers?
Asked Answered
H

9

45

In Java, are access specifiers and access modifiers the same thing?

Hamel answered 10/2, 2010 at 17:2 Comment(1)
Interesting, I've never seen this particular question before in years, but you're apparently not the only one who wondered about this: google.com/search?q=difference+access+specifier+access+modifier ;)Hola
B
48

"access modifier" is the official term for private, protected and public used in the Java language specification. "access specifier" is used synonymously in the Java API doc, but this is the first time I've noticed that. It's probably better to stick with the JLS term.

Bi answered 10/2, 2010 at 17:9 Comment(1)
+1 for proving with the JLS. I think that it's after all just the language barrier.Hola
V
7

The term Access specifier used by c++ programmers not in java. In java Officially we use Access Modifier.

For example: when we declare a class with private, static the compiler clearly shows the error message as follows:
enter image description here

Valuation answered 9/1, 2016 at 1:31 Comment(0)
O
6

Referring to the Sun Java Docs they both seem to be the same:

Overman answered 10/2, 2010 at 17:16 Comment(0)
A
1

Java has basically 2 types of Modifiers:

  1. java access modifiers
  2. java non-access modifiers

Java access modifiers and Java access specifiers are the same thing, which are public, private, protected.

Aubreyaubrie answered 22/5, 2012 at 5:59 Comment(0)
C
1

In some older languages public, private, protected and default like C++ are considered as access specifiers and everything else is considered as access modifier but in Java there is no terminology for specifier, everything is by default considered as modifier only. So public, private, protected, default, final, abstract, static, strictfp, synchronized, native, transient and volatile are all modifiers only.

Simple test for it is when we compile the following code

private class Test{ }

we will get compile time error saying that modifier private not allowed here. This is true for other modifiers also. Maybe java compiler (javac) sees everything as a "modifier" only.

Christiechristin answered 26/8, 2014 at 3:10 Comment(0)
T
1

There is nothing known as "Access specifiers" in java, there are only Access modifiers in java

The misconception is from languages like C++ where public, private, protected, default are considered as Access specifiers and remaining (static, final, etc) are considered as access modifiers

Following is the proof as compiler says "modifier private not allowed here" i.e. compiler said modifier and not specifier

enter image description here

Thimbleweed answered 29/8, 2020 at 9:52 Comment(0)
G
0

According to me, yes, both terms refer to the same thing and are used interchangeably.

Gnathion answered 10/2, 2010 at 17:12 Comment(1)
It's not up to you, it is up to the JLS, and the term 'access specifier' doesn't appear there at all.Norling
N
0

That JDI reference is the only place I have ever seen the term 'access specifier' used in a Java specification. Even there, public/protected/private/package are also called 'modifiers'. There's really no reason to ever use the term 'access specifier' in Java, it is clearly just a mistake on one page out of many thousands.

Norling answered 15/2, 2010 at 0:31 Comment(0)
P
-4

Technically speaking private, public, protected and default are treated as access specifiers. These deal with who can ... questions. The modifiers afaik are volatile, final, static, transient etc. These deal with how does .. aspect.

Pages answered 10/2, 2010 at 17:12 Comment(1)
Please provide a JLS citation for this assertion. It is baseless.Norling

© 2022 - 2024 — McMap. All rights reserved.