Search code examples
javaaccess-modifiersaccess-specifier

Abstract and final are access modifiers or access specifiers


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.


Solution

  • 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