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

Packages

 
Daslan Govender
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it correct to say that when defining an interface, the only access
modifier that a method can have is public? In fact the method signiture
can be specfied without being prefixed by public.


If this is true, why when I define an interface in a package and I try to
implement the interface outside the package, I get a compile error saying that the interface is not public in the package? It works perfectly
if the method signiture in the interface is prefixed by public.
 
M Beck
Ranch Hand
Posts: 323
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you're writing an interface, and you're declaring some part of it as being something other than public, and the javac compiler is not telling you there's an error on that particular line... then you can, clearly, declare things to be other than public in an interface. however, doing so may or may not make any sense, and the error you're seeing might be happening because the remainder of your code (viewed as a whole) turns out not to make sense.
 
Divya Mehrotra
Greenhorn
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you do not specify public modifier, your interface will be accessible only to classes that are defined in the same package as the interface.

please refer the following link :-

http://java.sun.com/docs/books/tutorial/java/interpack/interfaceDef.html
 
Daslan Govender
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.
 
Layne Lund
Ranch Hand
Posts: 3061
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, a method in an interface can ONLY be public. However, there is a difference between the visibility of the methods and the visibility of the interface itself and the methods in the interface. If the interface itself is not declared public, it doesn't generally matter what visibility the methods have.

Layne
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic