Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using abstract keyword in interface

Tags:

java

oop

I know the difference between "public interface" and "public abstract interface", but when applied on methods are there differences?

public interface IPluggableUi {
    abstract public JComponent getPanel();
    abstract public void initUi();
}

or

public interface IPluggableUi {
    public JComponent getPanel();
    public void initUi();
}
like image 918
Steel Plume Avatar asked Apr 26 '09 18:04

Steel Plume


2 Answers

Methods declared in interfaces are by default both public and abstract.

Yet, one could:

public interface myInterface{
     public abstract void myMethod();
}

However, usage of these modifiers is discouraged. So is the abstract modifier applied to the interface declaration.

Particularly, regarding your question:

"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."

source: http://java.sun.com/docs/books/jls/second_edition/html/interfaces.doc.html

Section 9.4: Abstract method declarations.

like image 65
Tom Avatar answered Sep 22 '22 14:09

Tom


no, you could also write

public interface IPluggableUi {
    JComponent getPanel();
    void initUi();
}

its the same thing

like image 27
IAdapter Avatar answered Sep 23 '22 14:09

IAdapter