3

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?

coder5
  • 67
  • 2
  • 7

4 Answers4

6

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.

RanRag
  • 48,359
  • 38
  • 114
  • 167
2

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

Gus
  • 6,719
  • 6
  • 37
  • 58
2

Both are syntactically correct but

public abstract void myMethod();

is more common. You usually declare the visibility first.

mtsz
  • 2,725
  • 7
  • 28
  • 41
1

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.

fivedigit
  • 18,464
  • 6
  • 54
  • 58