0

Say I have a Interface FirstInterface as follows :

  public interface FirstInterface {
    public void myInterfaceMethod();
}

Here I am declaring a method myInterfaceMethod() which will be defined in the class that will implement this Interface.

but I can also do

public interface FirstInterface {
    public abstract void myInterfaceMethod();
}

I have added a keyword abstract in the method declaration. I want to know, if at all, does it make any difference to add a abstract keyword in the method declaration or not?

Himanshu Gupta
  • 77
  • 1
  • 1
  • 9

1 Answers1

3

All non-default, non-static methods in interfaces are abstract by default. Adding the keyword is harmless, but changes nothing and is discouraged by the JLS "as a matter of style."

From JLS§9.4:

An interface method lacking a default modifier or a static modifier is implicitly abstract... It is permitted, but discouraged as a matter of style, to redundantly specify the abstract modifier for such a method declaration.

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875