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.
1.接口可以声明为public(公共)或默认的访问权限。接口隐含表明是抽象的(abstract)的。 2.接口的方法默认即为public(公共)且是abstract(抽象)的. 3.接口中的变量默认即为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.
Interfaces specify the set of methods that have to be implemented ultimately by a concrete (non-abstract class).
Abstract will specify a method which is not implemented in an abstract base class, and that must be implemented in a concrete subclass.
A side note; Values defined in an interface are public static final my default so
int VALUE = 5;
is the same as
public static final int VALUE = 5;
in an interface.
abstract Interfaces
Every interface is implicitly abstract . This modifier is obsolete and should not be used in new programs.