0

Can anyone tell me difference between specifying interface public and abstract?

public interface Test{} 

and

abstract interface Test{}
Buhake Sindi
  • 87,898
  • 29
  • 167
  • 228
prarane
  • 39
  • 9

5 Answers5

4

The former is an interface that can be accessed from anywhere. The latter (since abstract is superfluous) is an interface that can be accessed within the same package, as it has default access modifiers.

nanofarad
  • 40,330
  • 4
  • 86
  • 117
0

Interfaces are implicilty abstract. So abstract interface is not needed.

From JLS : http://docs.oracle.com/javase/specs/jls/se7/html/jls-9.html#jls-9.1.1.1

9.1.1.1. abstract Interfaces

Every interface is implicitly abstract.

This modifier is obsolete and should not be used in new programs.

Ajay George
  • 11,759
  • 1
  • 40
  • 48
0

It is redundant to declare an interface as abstract as they are all abstract by definition. The only difference, then, is the public component. Your first interface (which is public) can be accessed from anywhere whereas your second (which has default visibility) is package-private, meaning it can only be accessed within its own package.

arshajii
  • 127,459
  • 24
  • 238
  • 287
0

public abstract interface means it will be available in all the packages. But abstract interface will only be available in the current package because of the default access. Read more about access specifiers here:

http://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html

And packages are abstract by nature, which means they cannot be isntantiated. And all the methods in the package will be abstract. Having the purely abstract method, mandates an implementing class to override them.

Juned Ahsan
  • 67,789
  • 12
  • 98
  • 136
0

As always, the JLS provides the answer (JLS 9.1.1.1):

Every interface is implicitly abstract.

Of course, I'm assuming that you mean to include the public modifier on your second example. If you don't, then there are other differences between the two -- but they do not relate to the abstract keyword.

asteri
  • 11,402
  • 13
  • 60
  • 84