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

UK seeks future cyber-security starsPosted on Friday November 17, 2017

UK initiatives aim to get young people choosing a career in cyber-security to close a looming skills gap.

Apple delays launch of smart speakerPosted on Friday November 17, 2017

The HomePod will now go on release in early 2018 as the gadget still needs work, said Apple.

Germany bans children's smartwatchesPosted on Friday November 17, 2017

Telecoms regulator says kids' smartwatches are spying devices and are to be banned under German law.

Courtesy BBC News

AD BLOCKER DETECTED!

Advertisements help running this site for free.


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

×