What is abstract interface in Java?

An interface in Java is implicitly abstract and adding that modifier is considered redundant and makes no difference. Section 9.1.1.1 of Java language specification mentions that every interface is implicitly abstract whether you type in the abstract modifier or not. This modifier is obsolete and should not be used in new programs. Hence, both of the following declarations are legal, and functionally identical:

public abstract interface Bounceable { }
public interface Bounceable { }

The public modifier is required if you want the interface to have public rather than default access.

We have seen that abstract modifier in interface declaration statement is discouraged; now look closely at the methods within an interface:

public interface Bounceable 
{
  public abstract void bounce();
  public abstract void setBounceFactor(int bf);
}

Typing in the public and abstract modifiers on the methods declared in an interface is redundant because all interface methods are implicitly public and abstract. Given that rule, we can see that the following code is exactly equivalent to the preceding interface:

public interface Bounceable 
{
  void bounce();                // No modifiers
  void setBounceFactor(int bf); // No modifiers
}

Java language specification states that it is permitted, but discouraged as a matter of style, to redundantly specify the public and/or abstract modifier for a method declared in an interface.

Interface methods must not be static. Because interface methods are abstract, they can also not be marked final.

Hope you have enjoyed reading about abstract interface in Java. Please do write us if you have any suggestion/comment or come across any error on this page. Thanks for reading!



Share this page on WhatsApp

Get Free Tutorials by Email

About the Author

is the founder and main contributor for cs-fundamentals.com. He is a software professional (post graduated from BITS-Pilani) and loves writing technical articles on programming and data structures.