java - Why should we declare interface methods as public? -
this question has answer here:
- protected in interfaces 13 answers
when implement interface
method, forced make public
method.
we may have cases want use either default
(like in case of access within same package) or protected
.
can please explain reason behind limitation?
interfaces meant define public api of type - , that, not implementation. method (or static member) define in interface definition public
.
since interface can't contain concrete implementation, there no way call member methods within. , declaring such methods leaving calls them subclasses or totally unrelated clients mean type definition incomplete , brittle. why if need define protected or package access members, can in abstract class (which may contain implementation).
Comments
Post a Comment