Click here to Skip to main content
14,733,513 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
See more:
Hi to all,

As we know in an interface all methods must be public, we can not define private or protected methods. If we will try then compiler will give the error because its definition of the interface.

My question is why interfaces do not accept access modifiers other then public and what are the reasons behind it?

Thanks in advance :)
--Amit
Posted
Updated 23-Mar-10 2:36am
v2

Because that is the definition of an interface.
In C++ it is still possible to have access specifiers for an interface because an interface is nothing but a struct.
   
am.net wrote:
my question is, Why interfaces not accept access modifiers other then public, what is the reason behind this???


What would be a reason behind non-public interfaces ? :)

All non-public methods of a class could be accessed directly
(, if you have an appropriate this-context...
...that is not a case at an interface call) :)
   
v2
Because that's the interface definition (an interface is a contract).
What would be the sense of a private method in a interface?
:)
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900