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!




Get Free Tutorials by Email

About the Author

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

Today's Tech News

WannaCry ransom notice analysis suggests Chinese linkPosted on Monday May 29, 2017

Researchers say the WannaCry ransom note was poorly translated - possibly using Google Translate.

BA boss 'won't resign' over flight chaosPosted on Monday May 29, 2017

Chief executive Alex Cruz says flight disruption at Heathrow and Gatwick had nothing to do with cost cutting.

Hay Festival 2017: Stephen Fry's warning for the webPosted on Sunday May 28, 2017

Delivering a lecture at the Hay Festival, the actor said society could face "dire consequences".

Courtesy BBC News