C
Chris Berg
Why do methods of an interface have to be public? Couldn't they be
'package', or even 'protected'?
The immediate answer would be no, because conceptually, an interface
is a sort of specification that tells the world what to expect from
the implementing class. But why the whole world? Would it not make
sense to limit (at least some of) the methods to 'package' access?
'Protected' would maybe be somewhat more far-fetched, as limiting
access to subclases makes it meaningless to specify the method in the
interface in the first place. Or does it?
But allowing 'package' would allow you to not javadoc all the
interface's methods, some of which could be irrelevant outside the
pakage.
Chris
'package', or even 'protected'?
The immediate answer would be no, because conceptually, an interface
is a sort of specification that tells the world what to expect from
the implementing class. But why the whole world? Would it not make
sense to limit (at least some of) the methods to 'package' access?
'Protected' would maybe be somewhat more far-fetched, as limiting
access to subclases makes it meaningless to specify the method in the
interface in the first place. Or does it?
But allowing 'package' would allow you to not javadoc all the
interface's methods, some of which could be irrelevant outside the
pakage.
Chris