This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Interfaces implicitly public? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Interfaces implicitly public?" Watch "Interfaces implicitly public?" New topic
Author

Interfaces implicitly public?

Nidhi Sar
Ranch Hand

Joined: Oct 19, 2009
Posts: 252

Hi,

As per my understanding, all the methods & variables in an interface are implicitly public, but the interface itself May have public or package access. Is that correct?

So here:


i & myMethod() are implicitly public but Bounceable has package access.

Am I correct?


"A problem well stated is a problem half solved.” - Charles F. Kettering
SCJP 6, OCPJWCD
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

You're somewhat correct.

Methods in a interface are implicit public and variables are implicit public static and final!
Non-inner interface may have default or public access. However an inner interfaces may
have all accesslevels.



"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Nidhi Sar
Ranch Hand

Joined: Oct 19, 2009
Posts: 252

Wouter Oet wrote:However an inner interfaces may
have all accesslevels.



Thanks Wouter!! Glad to know that I was correct on the first part. But... what are inner interfaces used for. I know about the uses of inner classes, but inner inetrfaces???
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

An example of an inner interface is the java.util.Map.Entry interface. A public interface.
Nidhi Sar
Ranch Hand

Joined: Oct 19, 2009
Posts: 252

Wow, perfect example! Thanks Wouter
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

Glad I could help.
Muhammad Khojaye
Ranch Hand

Joined: Apr 12, 2009
Posts: 449

what are inner interfaces used for. I know about the uses of inner classes, but inner inetrfaces???

They make sense when the interface is only used in conjunction with the class.
Map.Entry point out by Wouter is a good example. The Entry interface is only associated with the Map, therefore they define it as nested interface. If Map.Entry defines as separate interface, then people can refer to Map.Entry outside of the context of a Map. Define Entry as part of a Map provides better understanding of relationship.

Oops... Too late...


http://muhammadkhojaye.blogspot.com/
 
Consider Paul's rocket mass heater.
 
subject: Interfaces implicitly public?