Pergunta

Quick question:

Is the proper syntax:

public abstract void myMethod();

OR

abstract public void myMethod();

... The difference being the order of the keywords public and abstract.

Both compile without warnings, but which is the proper syntax?

Foi útil?

Solução

According to JLS section 8.1.1

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

If two or more class modifiers appear in a class declaration, then it is customary, though not required, that they appear in the order consistent with that shown above in the production for ClassModifier.

Outras dicas

Either is "proper". The difference is a matter of style. I prefer the first.

Both are syntactically correct but

public abstract void myMethod();

is more common. You usually declare the visibility first.

Most common practice is public abstract. I can't actually recall any example or book or any code I've worked with that does the opposite.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top