Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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();
like image 268
kamaci Avatar asked Feb 07 '26 00:02

kamaci


1 Answers

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.

like image 53
Mat Avatar answered Feb 08 '26 13:02

Mat