0
abstract final class Outer {

}

So i was compiling the above code and got obvious error ,but the error was Illegal combination of access modifiers ,but the java doc http://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html says there are only 3 access modifiers (public ,private and protected ) So these abstract ,final,public ,private and protected are access modifiers or access specifiers or something else?because in many books and website they mentioned these keywords as sometimes access modifiers and sometimes access specifiers. i am so confused here.

user3690061
  • 118
  • 1
  • 3
  • 15

1 Answers1

3

In the context of class declaration, and according to the JLS #8.1.1, these are all class modifiers.

And if you read a bit further you will see that only public, private and protected are access modifiers (which makes sense: they determine whether the class is accessible or not from other parts of the code).

So yes, technically, abstract and final are not access modifiers and the error message could be more precise. Note that javac (Java 8) error message is:

illegal combination of modifiers: abstract and final

assylias
  • 321,522
  • 82
  • 660
  • 783
  • At first you say all(abstract ,final,public ,private and protected ) modifiers but next line you say only public ,private and protected are modifiers. what does it mean then? – user3690061 Jun 04 '14 at 15:03
  • @user3690061 these are all *modifiers* but only private, public and protected are ***access** modifiers*. – assylias Jun 04 '14 at 15:05
  • so there is nothing called access specifier? – user3690061 Jun 04 '14 at 15:08
  • @user3690061 not in the official documentation. The only reference to specifier in the JLS is in the context of *parameter specifier* which means the type and name of a method's parameter, like `int i` in `public void someMethod(int i) {}`. – assylias Jun 04 '14 at 15:10
  • So what could be the reason that people have mentioned access specifiers as public ,private and protected and access modifiers as abstract ,final. – user3690061 Jun 04 '14 at 15:15
  • 2
    @user3690061 Whoever told you final amd abstract were access modifiers was wrong. public, protected and private (package-private if you're counting implicit modifiers) are the only **access** modifiers. abstract, final, static, volatile, transient.. all of those are modifiers, but **not** *access modifiers* – Vince Jun 04 '14 at 15:19