Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Access modifer to interface

 
cathy liu
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
cathy liu
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks! Big help!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic