Why is the declared method of the interface declared public?

I just started learning Java when I came across the interface I saw the following code:

interface Callback {
   void callback(int param);


class Client implements Callback {
   public void callback(int p) {


why does it mean that the implemented method of the interface will be declared as public



source to share

2 answers

The default modifier for an interface method is public abstract

The default modifier for a class method is a local package. They are not the same and you cannot override a public method with a local package. You can override an abstract method with a non-abstract one.

You should make your class method public even if you don't need to embed it in the interface.



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



All Articles