Vishnu Vishnu - 8 months ago 23
Java Question

Why should we declare interface methods as public?

When I implement an

method, I am forced to make it a

We may have cases where we want to use either the
(like in case of access within the same package) or

Can anyone please explain the reason behind this limitation?


Interfaces are meant to define the public API of a type - and only that, not its implementation. So any method (or static member) you define in an interface is by definition public.

Since an interface can't contain any concrete implementation, there is no way to call any member methods from within. And declaring such methods but leaving the calls to them to subclasses or totally unrelated clients would mean your type definition is incomplete and brittle. That is why if you need to define protected or package access members, you can do so in an abstract class (which may also contain implementation).