java - Why should we declare interface methods as public? -


this question has answer here:

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

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -