I'm reading SCJP by Kathy Sierra and Bert Bates and it says on pg. 21 that "The public modifier is required if you want the interface to have public rather than default access". Is this true? If yes, then the interface methods (which are always public) only accessible if the interface is in the same package of the implementing class...? Since that is the meaning of the default access modifier...I'm a bit confused on this.

2

There are 2 best solutions below

0
On BEST ANSWER

Is it true that if you don't specify an access modifier for an interface, that interface will have default access?

Yes that is true. Java types/fields/methods (in class) have package-level access if access modifier is not specified. Members defined in inteface type are public by-default.

Read tutorial - Controlling Access to Members of a Class.

0
On

Here the interface itself is package protected but the methods are always public by default

interface Foo
{
    void bar(); // this is always public and nothing else
}

Here the interface is public as well as the methods

public interface Foo
{
    void bar(); // this is always public and nothing else
}

you can declare public void bar(); or void bar(); they mean the same thing, personally, I always put the public because explicit is always better than implicit