It's not a secret anymore!*
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Interface" Watch "Interface" New topic
Author

Interface

Moon Winter
Greenhorn

Joined: Sep 02, 2001
Posts: 20
Question 6.
An Interface can never be private or protected.
Answers
True
False
The answer given is False. Can anyone give out an example which an interface is private or protected (including inner interface).
Thanks!
Moon
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.
HTH
--Farooq
e.g.
===============================================================
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:
10
I think it is a good example to prove the question.And if you try to compile this code:

The compiler will complain:
Test8.java:1: 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: http://aspose.com/file-tools
 
subject: Interface
 
Similar Threads
Can an interface be private/protected?
Interface question
from mock exam
Interface
Interfaces