Forums Register Login

Interfaces implicitly public?

+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
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.

+Pie Number of slices to send: Send
 

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???
+Pie Number of slices to send: Send
An example of an inner interface is the java.util.Map.Entry interface. A public interface.
+Pie Number of slices to send: Send
Wow, perfect example! Thanks Wouter
+Pie Number of slices to send: Send
Glad I could help.
+Pie Number of slices to send: Send
 

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...
But how did the elephant get like that? What did you do? I think all we can do now is read this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 2273 times.
Similar Threads
K&B page no 121 doubt
interface error
Polymorphic behavior provided by inheritance programming assignment
SCJP for Java 6 book by Sierra and Bates covariant return code example question
Interface Question
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 08:49:33.