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

Bees 'go online' in ManchesterPosted on Friday September 22, 2017

Rory visits a beekeeper in Manchester who is gluing wireless chips to his bees.

The long wait for a Persian iPhone keyboardPosted on Friday September 22, 2017

The new Apple's iOS has Persian keyboard. BBC Persian's Sam Farzaneh discusses why it is an important feature.

Uber London loses licence to operatePosted on Friday September 22, 2017

Ride-hailing app Uber is "not fit and proper" to operate in London, the transport regulator says.

Courtesy BBC News

AD BLOCKER DETECTED!

Advertisements help running this site for free.


To view the content please disable AdBlocker and refresh the page.

×