• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

interface

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!
Can an interface to be private or protected in some cases??
Thank you in advance.
 
Ranch Hand
Posts: 267
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is from sun's tutorial
"Member declarations in an interface disallow the use of some declaration modifiers; you cannot use transient, volatile, or synchronized in a member declaration in an interface. Also, you may not use the private and protected specifiers when declaring members of an interface. "
From this I assume you cannot have these modifiers for the interface declaration either..
Others correct me if I am wrong.

Originally posted by Jordi Marqu�s:
Hi!
Can an interface to be private or protected in some cases??
Thank you in advance.


 
Roopa Bagur
Ranch Hand
Posts: 267
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is from the spec doc.You are right about using private & protected modifiers in some cases..
"Not all modifiers are applicable to all kinds of interface declarations. The access modifiers protected and private pertain only to member interfaces within a directly enclosing class declaration and are discussed in �8.5.1. The access modifier static pertains only to member interfaces (�8.5, �9.5). A compile-time error occurs if the same modifier appears more than once in an interface declaration."
NOTE: Member interfaces are those that are declared inside a class.
Hope this helps.

Originally posted by Jordi Marqu�s:
Hi!
Can an interface to be private or protected in some cases??
Thank you in advance.


 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what about inner interfaces.
The private or protected modifiers can be used with inner interfaces.
e.g.
class Outer {
private interface IFInner {}
}
This code compiles just fine.
Hope this helps.

------------------
Asma Zafar,
Sun Certified Programmer for Java2 Platform
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hola Jordi
See this link to see Inner classes or interface in action:
http://codeguru.earthweb.com/java/tij/tij0081.shtml
 
Slideshow boring ... losing consciousness ... just gonna take a quick nap on this tiny ad ...
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic