File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Access modifer to 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 "Access modifer to interface" Watch "Access modifer to interface" New topic
Author

Access modifer to interface

cathy liu
Greenhorn

Joined: Sep 07, 2006
Posts: 9
Hi,

I have some confusion about the access modifier for interface based on K&B book.

I know the methods and constant in the interface is implicitly public. I assume the interface declaraction would be the same too.

But on page 21 of K&B book, it said "The public modifier is required if you want the interface to have public rather than default access".

So my question is which access modifers are valid for interface? Does it only include "public" and "default".

What happen if I declare an interface and have no access modifier? Does it mean the interface could only be implemented by the classes in the same package?


Thanks for the help!
Priya Viswam
Ranch Hand

Joined: Dec 28, 2006
Posts: 81
Only public and default access modifiers can be applied to top level interface. If no access modifier is specfied, then it can be implemented only by the classes in the same package.

If the interface is defined inside a class, then we can use any access specifier. But if it is defined inside another interface, only public access modifier is allowed.


SCJP 1.5<br />SCWCD 1.4
cathy liu
Greenhorn

Joined: Sep 07, 2006
Posts: 9
Thanks! Big help!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Access modifer to interface
 
Similar Threads
Default access modifier of interface
Interface and Implementin class
what is right....and why???
Interfaces - public and abstract
Interface doubt