Interfaces in Java: cannot make implemented methods protected or private

jbu picture jbu · Jan 8, 2009 · Viewed 37.1k times · Source

I know that an interface must be public. However, I don't want that.

I want my implemented methods to only be accessible from their own package, so I want my implemented methods to be protected.

The problem is I can't make the interface or the implemented methods protected.

What is a work around? Is there a design pattern that pertains to this problem?

From the Java guide, an abstract class wouldn't do the job either.

Answer

duffymo picture duffymo · Jan 8, 2009

read this.

"The public access specifier indicates that the interface can be used by any class in any package. If you do not specify that the interface is public, your interface will be accessible only to classes defined in the same package as the interface."

Is that what you want?