1
votes

In section 8.1.1 Class Modifiers of the Java Language Specification 8, it states that:

ClassModifier: one of
    Annotation public protected private abstract static final strictfp

But I managed to compile the following:

public strictfp A{}

That is, it states that one of the class modifiers should be chosen but I was able to choose more than one. Am I misinterpreting the specification here?

2
did you read three lines before what you pasted? "A class declaration may include class modifiers. ClassModifiers: ClassModifier ClassModifiers ClassModifier" - SMA
I'm sure you meant java7, in java8 it doesn't state that - msrd0
@msrd0 java 8 JLS doesnt have above line. Refer here So OP is reading SE 7's JLS and assuming its for 8. - SMA
@almasshaikh I know, I read that and thats why I think the OP means Java7 - msrd0
It does have that line in the pdf version. - M.K.

2 Answers

6
votes

The answer is in the rule above:

ClassModifiers:
    ClassModifier
    ClassModifiers ClassModifier <<== Here

ClassModifier: one of
    Annotation public protected private abstract static final strictfp

Essentially, the rule says that you can use one or more ClassModifiers in a ClassModifiers list. This recursive definition of an iterative concept of "one or more" is common for BNF-style syntax descriptions (as opposed to EBNF, that provide a special syntax for repetitions).

5
votes

The ClassModifiers Java Language Specification tells exactly :

ClassModifiers:
    ClassModifier
    ClassModifiers ClassModifier

ClassModifier: one of
    Annotation public protected private
    abstract static final strictfp

So it is either 1 or more ClassModifier before the class