Two Laptop Bag*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Question on Interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Question on Interface" Watch "Question on Interface" New topic
Author

Question on Interface

Reshma Shanbhag
Ranch Hand

Joined: Sep 17, 2002
Posts: 203
Hi All,
I have a question regarding Interfaces. Can an Interface be private or protected??.
I tried working with top level interfaces .. the complier complains. But i get to hear that inner Interfaces can be private or protected. I have no much idea about inner interfaces.. and i dont know what i tried was correct .
I tried the following example
interface Check_Inner_Interface{

void aMethod();

private interface Inner_Private{

}

protected interface Inner_Protected{

}

}
When i try to compile i get the following message ..
Check_Inner_Interface.java:5: illegal combination of modifiers: public and private
private interface Inner_Private{
^
Check_Inner_Interface.java:9: illegal combination of modifiers: public and protected
protected interface Inner_Protected{
^
2 errors
It would be of help if u help me to clear this confusion.


SCJP 1.4, SCWCD 1.4
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
What you did is "almost" correct. You can indeed have private/protected inner interface but only in classes.
If you declare an interface within another interface it will automatically be public since all members of an interface must be public (and are made implicitely public) otherwise what good would be an interface if some of its members can be private? When you compile your code you get the "illegal combination of modifiers" thing, because the compiler automatically adds a public modifier to all members within the interface and an interface cannot be public and private at the same time. Makes sense, doesn't it?
Hope this clears your doubts.
[ January 29, 2003: Message edited by: Valentin Crettaz ]

SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question on Interface