Hi: It would be nice if some one could answer this question regarding the accessor modifiers for members in an interface. Rule: members declared inside the interface are implicitly public. My analysis: 1- members can not be private as it would be useless as methods in interface are abstract. 2- members can not be protected as class implement interface but does not extend it. But why can not they be "package visible" ? or, please explain the philosphy behind making the members in an interface always "public" regards Kapil
Well, what use would it be to allow interfaces to declare package-accessible methods? This would mean that the whole interface could only be used within its own package. Assuming there's actually a use for this, you can achieve the same effect by making the whole interface package-accessible. (I.e. declare it as "interface" rather than "public interface".) Note that the existing rules say that an interface's members are implicitly public - but that doesn't apply to the interface as a whole, which can be package or public, just like a class. (Nested classes or interfaces can also be private or protected; I'm just taking about top-level classes and interfaces.)
Just remove the word "public", and now the interface cannot be used at all outside the current package. It's a little weird, because the methods now technically have public access while the interface does not. But the public access is meaningless here since no one outside the package can make any use of the interface. It's like saying "all the rooms in this buiding are unlocked, but not any of the outside doors." If you can't get in the building, it doesn't matter whether the inner doors are locked or not.
Originally posted by Jim Yingst: "all the rooms in this buiding are unlocked, but not any of the outside doors." If you can't get in the building, it doesn't matter whether the inner doors are locked or not.
Actually it is more like all the rooms in this buiding are unlocked, "but not any of the outside doors or you can come thru the ventalitors" if a public inteface extends the package level interface, then the former will contain the methods define in the latter. :roll:
tobe bondhu nouka bherao<br />shonabo gaan aj shara raat