Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Abstract methods in a Java interface

Something I've seen a lot but never thought to question it... In a Java Interface, what is the difference between:

public void myMethod();

and

public abstract void myMethod();

I understand the purpose of the abstract keyword in a Java class, but what purpose does it serve (if any) in an interface?

like image 814
seanhodges Avatar asked Mar 18 '11 10:03

seanhodges


2 Answers

Both declarations are completely the same, all interface methods do not have implementation (are abstract) hence the abstract keyword is redundant. In my opinion writing abstract in this case increases verbosity of code.

like image 50
nan Avatar answered Sep 22 '22 07:09

nan


All method declarations are both public and abstract in an interface. No point specifying it at all.

Only void myMethod(); is really needed here.

like image 43
Goran Jovic Avatar answered Sep 23 '22 07:09

Goran Jovic