File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Interface 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 "Interface" Watch "Interface" New topic


Moon Winter

Joined: Sep 02, 2001
Posts: 20
Question 6.
An Interface can never be private or protected.
The answer given is False. Can anyone give out an example which an interface is private or protected (including inner interface).
Muhammad Farooq
Ranch Hand

Joined: May 08, 2001
Posts: 356
Only an interface declared in a class can be declared private or protected, thats why the answer is false. The word "NEVER" is used in the question.
class InterfaceTest{
private interface privateinterface{}
protected interface protectedinterface{}
[This message has been edited by Muhammad Farooq (edited September 02, 2001).]

Muhammad Farooq<br />Sun Certified Programmer for Java 2 Platform<br />Oracle8i Certified Professional Database Administrator
Metal Zhang
Ranch Hand

Joined: Aug 05, 2001
Posts: 52
Please try to compile and run this code:

The output is:
I think it is a good example to prove the question.And if you try to compile this code:

The compiler will complain: The type type Foo can't be private. Package members are always accessible wi
thin the current package.
private interface Foo{
1 error

Java lover from hell!

Java lover from hell!
I agree. Here's the link:
subject: Interface
It's not a secret anymore!