aspose file tools*
The moose likes Beginning Java and the fly likes Interface issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Interface issue" Watch "Interface issue" New topic
Author

Interface issue

edirg559
Greenhorn

Joined: Apr 19, 2006
Posts: 19
Ranchers:

I know that all methods inside the interface are abstract and meant to be overriden (even though we did not explicitly declare those methods public abstract, it is automactically declared for us). Is this mean:

1. Methods inside interface have to be kept public all the time?
2. Can we declare type of the method others besides void?
3. Can we have paramateres on the methods?
4. Can we have a static methods in interface?

Examples
which of these are valid declarations in a interface definition:
1. void methoda ();
2. public double mothoda ();
3. public final double mothoda();
4. static void methoda (double d1);
5. protected void methoda (double d1);

Thanks,
Erik
edirg559
Greenhorn

Joined: Apr 19, 2006
Posts: 19
Because of my impatience, I have tried running all the scenarios. The result are:

1. Yes, methods have to be kept public inside interface.
2. Yes
3. Yes
4. If we try to decare a static method, we will get a response "modifier static not allowed here"

So, I assume for the 4 examples case no 1&2 are valid ones. One more point, final method is not allowed in interface because final means can not be overriden, as we know the purpose of having abstract methods are to be overriden by classes which implement the interface.

Erik
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by Erik Dirgaria:
...I have tried running all the scenarios...

That's often the best way to learn!

Interface methods are implicitly abstract and public. (These keywords can be included, but are not required.)

There are no restrictions on return or argument types. But abstract methods cannot be static. And because methods cannot be overridden with more restrictive access, interface methods must stay public.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Interface issue