Witscale Test Center

3.7 Interface and modifiers > 3.7.1 Interface methods and modifiers


3.7.1 Interface methods and modifiers

An interface is meant to only describe the common public behavior. Any class implementing an interface needs to implement the common behavior that the interface describes. Therefore, the methods of an interface have no implementation and they are all abstract by default.  They are also implicitly public.  You can redundantly specify them as abstract and public. For instance, in the following code, the search methods are public and abstract:

 

public abstract interface Searchable {

  void Search(String searchString);

  void Search(String searchString, boolean ignoreCase);

}

 

The search() methods do not seem to have any access modifiers. However, it does not mean that they have a default access. They all implicitly have a public access because they are interface methods.

 

Interface methods are the exceptional case where the lack of access modifier does not mean the default access.

 

Because interface methods are abstract, it does not make sense to declare them as static, final, native or synchronized. Therefore you are not allowed to use these modifiers with interface methods.