| 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: 341
|
|
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/
|
 |
 |
|
|
subject: Interfaces implicitly public?
|
|
|