aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Private/Protected interfaces Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Private/Protected interfaces" Watch "Private/Protected interfaces" New topic
Author

Private/Protected interfaces

Shafeeq Sheikh
Ranch Hand

Joined: May 12, 2000
Posts: 68
There's a question in Abhilash's exam that goes like this:
An Interface can never be private or protected.
True
False
The given answer is FALSE.....
But I wrote this program:
private interface Int
{
void someMethod();
}
public class AQuestion implements Int{
public void someMethod(){
System.out.println("from the implemented method");
}
}
and the compiler complains..... Even if I change the access modifier to protected (for the interface)..... it complains again....
Is the answer in his exam wrong or am I missing something???
Thanks in advance.....
Savithri Devaraj
Ranch Hand

Joined: Jun 26, 2000
Posts: 103
It looks like a top level interface cannot be private or protected.
I modified your code as below and it works just fine
public class AQuestion {
private interface xint{
void someMethod();
}
class newc implements xint{
public void someMethod(){
System.out.println("from the implemented method");
}
}
public static void main(String args[]){
AQuestion.newc aq = new AQuestion().new newc();
aq.someMethod();
}
}
Savithri Devaraj
Ranch Hand

Joined: Jun 26, 2000
Posts: 103
where is Abhilash's exam? Anywhere online??
Savithri
Shafeeq Sheikh
Ranch Hand

Joined: May 12, 2000
Posts: 68
There you go:
http://www.angelfire.com/or/abhilash/Main.html
Shafeeq Sheikh
Ranch Hand

Joined: May 12, 2000
Posts: 68
There you go...
http://www.angelfire.com/or/abhilash/Main.html
chetan nain
Ranch Hand

Joined: Jun 21, 2000
Posts: 159
interfaces may only be declared public or package access(no access modifier).
 
jQuery in Action, 2nd edition
 
subject: Private/Protected interfaces