質問

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?

役に立ちましたか?

解決

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.

他のヒント

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top