File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Interface issue

 
edirg559
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11343
Java Mac Safari
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic