|
To summarize the modifiers in relation with interfaces, note that
Interface can be declared with either public or default access.
It is implicitly abstract.
Interface methods are by default public and abstract.
Interface variables are by default public, static and final.
Table 3.3 shows the various combinations for the interface methods and constant declarations and how the compiler sees them.
Table 3.3 Valid declarations of interface methods and constants
|
Interface declarations |
How the compiler interprets them |
|
public interface Searchable {} |
public abstract interface Searchable {} |
|
abstract interface Searchable {} |
abstract interface Searchable {} |
|
interface Searchable {} |
abstract interface Searchable {} |
|
void search(String searchString); |
public abstract void search(String searchString); |
|
abstract void search(String searchString); |
public abstract void search(String searchString); |
|
public void search(String searchString); |
public abstract void search(String searchString); |
|
char MATCH_ONLY_ONE = ?; |
public static final char MATCH_ONLY_ONE = ?; |
|
public char MATCH_ONLY_ONE = ?; |
public static final char MATCH_ONLY_ONE = ?; |
|
static MATCH_ONLY_ONE = ?; |
public static final char MATCH_ONLY_ONE = ?; |
|
final char MATCH_ONLY_ONE = ?; |
public static final char MATCH_ONLY_ONE = ?; |
|
final public char MATCH_ONLY_ONE = ?; |
public static final char MATCH_ONLY_ONE = ?; |
|
|
|
|
|
The order of modifiers does not matter in any variable or method declaration. For instance, the declaration public abstract static method(); is same as the abstract public static method();. It is also the same as abstract static public method();. By convention, however, the access modifier (if any) is written before the other modifiers. |