Difference between interface and abstract interface in java

11,446

Solution 1

There is no such thing as abstract interface in Java (as interface is abstract by default), there is Abstract class.

The main difference between an abstract class and an interface, is that abstract class is inherited (extended), as normal class, so you cannot extend two of them in parallel, while you can implement more than one interface at the same time.

Solution 2

The abstract keyword is obsolete when working with Java interfaces, as a java interface by definition is abstract; it contains no implementation but only definitions.

Solution 3

Interfaces are already abstract. Remember the key term "abstract" as it relates to OOP means that you can't create an instance of itself, you can only use it as a base class from which you can derive your own objects from it.

Interfaces by their very nature are abstract in that they don't define any code themselves, but must be implemented by classes which then provide the functionality of the methods in the interface.

So you can add the word "abstract" to the front of an interface and nothing will happen any differently. Even in the java documentation awhile back the writers made an error by including "abstract" in the wording for interfaces.

But you just need to know that all interfaces are abstract and there is no difference.

Check this link

Share:
11,446
Brad
Author by

Brad

-

Updated on June 05, 2022

Comments

  • Brad
    Brad almost 2 years

    Like the title says. What is the difference between an interface and an abstract interface in Java?

  • Brad
    Brad almost 12 years
    Strange. I decompiled a jar and came across public abstract interface Blah. Hence the question. It does compile still, which is weird.
  • Donal Fellows
    Donal Fellows almost 12 years
    @Brad That's really a decompiler bug; all interfaces are always abstract. (At a guess, the “is abstract” bit is set in the class descriptor so the decompiler is issuing that word in its decompiled output, despite it also being an interface and so not necessary to do so. I didn't know that javac will accept it; guess it's “mostly harmless” here.)