문제

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