kamaci
kamaci

Reputation: 75127

What is the difference specifying abstract or not for interface methods?

What is the difference between specifying the abstract keyword on a method of an interface in Java, and not specifying it?

Like:

public void foo();
public abstract void foo();

Upvotes: 3

Views: 160

Answers (2)

KIMA
KIMA

Reputation: 1077

there is no difference all methods in interfaces are implicit abstract because to implement that interface all methods must be overriden ... strange that it´s working however

Upvotes: 0

Mat
Mat

Reputation: 206679

There is no difference. See the JLS Interfaces - Abstract Method Declatations:

Every method declaration in the body of an interface is implicitly abstract, so its body is always represented by a semicolon, not a block.

Also note:

For compatibility with older versions of the Java platform, it is permitted but discouraged, as a matter of style, to redundantly specify the abstract modifier for methods declared in interfaces.

Upvotes: 11

Related Questions