tags:

views:

204

answers:

3

Is there any difference between:

interface A{
    public a();
}

and

interface A{
    abstract a();
}

and

interface A{
    a();
}
+10  A: 

public and abstract are superfluous on interface methods so the three are identical.

Personally I always use the third one.

cletus
+12  A: 

From section 9.4 of the Java Language Specification:

Every method declaration in the body of an interface is implicitly abstract...

Every method declaration in the body of an interface is implicitly public.

Brandon E Taylor
A: 

Personally I prefer to explicitly declare my interface methods public. Although it is superfluous, in other contexts a method without a modifier is package-private, so I find it can be confusing, especially in interfaces with a lot of static final fields, to imply public in some contexts and package-private in others, when it may not be immediately obvious that you are looking at an interface if you drill to the method from your IDE and don't see the top of the declaration

But I find abstract is superfluous, since the method decalration ends with a semi-colon.

But these are all matters of style and preference. The functionality is exactly the same.

Yishai