• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Packages

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 323
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks.
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic