tags:

views:

454

answers:

5

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();
}
+2  A: 

no, you could also write

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

its the same thing

01
A: 

No. You can only apply abstract on a method to an abstract base class.

Interfaces specify the set of methods that have to be implemented ultimately by a concrete (non-abstract class).

Abstract will specify a method which is not implemented in an abstract base class, and that must be implemented in a concrete subclass.

(Note also that the public keyword is superfluous on method specifications on an interface)

Brian Agnew
+8  A: 

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.

Tom
A: 

A side note; Values defined in an interface are public static final my default so

int VALUE = 5;

is the same as

public static final int VALUE = 5;

in an interface.

Peter Lawrey
A: 

There is no public abstract interface in Java. All interfaces are "abstract" by the fact that they can't be instantiated. All the functions are automatically "abstract" since they need to be implemented.

Uri