Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
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


Win a copy of Java 8 in Action this week in the Java 8 forum!
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!
 
jQuery in Action, 2nd edition
 
subject: Access modifer to interface
 
Similar Threads
what is right....and why???
Interface and Implementin class
Interface doubt
Interfaces - public and abstract
Default access modifier of interface