Methods of interface
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Wednesday, June 4, 2003 06:05 AM

Why all methods of an interface should be public

Re: Methods of interface

Posted By:   Christopher_Koenigsberg  
Posted On:   Wednesday, June 4, 2003 07:30 AM

hmm, as far as I know (?) methods do not have to be declared "public", in an interface. I usually leave them as the default visibility, e.g. package, friendly, or whatever you call it.


Then in the implementation class, the visibility has to be equal to or greater than the visibility in the interface. So, by leaving it as the default on the method in the interface, I can either leave it as the default, or make it public, on the method in the implementation class.

Re: Methods of interface

Posted By:   Benoit_Quintin  
Posted On:   Wednesday, June 4, 2003 06:15 AM

Because an interface provides a set of methods that must be implemented by an object that can be _called_ by other objects. Like the java.sql.Connection interface rpovides methods that must be implemented, so that createStatement will be there, whatever DB you use.

You could probably have an abstract object and force implmenting protected methods but that's the best you'll get, since one never inherits private methods...

I think you should download Thinking In Java by Bruce Eckel, it would help.
About | Sitemap | Contact