jQuery in Action, 3rd edition
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

Access modifer to interface

cathy liu

Joined: Sep 07, 2006
Posts: 9

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

Joined: Sep 07, 2006
Posts: 9
Thanks! Big help!
I agree. Here's the link: http://aspose.com/file-tools
subject: Access modifer to interface
It's not a secret anymore!