This week's book giveaway is in the Agile and Other Processes forum. We're giving away four copies of Darcy DeClute's Scrum Master Certification Guide: The Definitive Resource for Passing the CSM and PSM Exams and have Darcy DeClute on-line! See this thread for details.
There can be situation where an Interface needs to be implemented by a class which is in different package as that of interface. But here the implementing class should have access to methods inside the interface.So we give public access specifier for class inside interface by default . and In implements clause , U can specify interface name with complete package extension (, which is not possible in case of methods) . Ex: class ABC implements com.ex.InterfaceEx
It is a contract of an interface that its methods are abstract and public to be implemented by any class from any class hierarchy or extended by any interface.
Sometimes you may require that a interface must only be accessed in its package only, not outside that. But in this case too, you can't violate the general contract of an interface of being abstract and public.
Suppose there is one interface that is public and that extends the interface that has default accessibility. Now a new interface you have created extending the existing one. This interface will be accessible from anywhere , no package only bound. If the previous interface method were having default accessibility as you guessed , now you can guess what would go wrong. Yes, violation of interface contract methods to be accessed. Any non-abstract class that implements the new interface must implement all the methods of both the interfaces. So all the methods must be public accessible.
It is the reason why methods of interface are public and abstract always irrespective of the accessibility of the interface itself.