I just started learning java when i came across interface, I saw the following code:
interface Callback {
void callback(int param);
}
class Client implements Callback {
public void callback(int p) {
}
}
why is that an implemented interface method be declared as public?
The default modifier for an interface method is
public abstractThe default modifier for a class method is package-local. These are not the same, and you can’t override a public method with a package local one. You can override an abstract method with a non-abstract one.
You have to make your class method public, even though you don’t have to put this in the interface.