Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Why Interface methods are public by default ?
Why cant we have a protected method in interface ?
Posted
Comments
Emrah Taylan 6-Jul-11 10:18am    
If you want to take 'inherit' your interface and
if I want to override your methods you must declare 'protected' , protected couldn't use like public,

Do u understand? İf you want I can send you example code?
adi007me 6-Jul-11 10:19am    
Little confusing ... Please send example code ...

1 solution

An interface is designed to provide a known and consistent "interface" to the outside world for classes that inherit it. There would be little point in having an interface with private methods defined.

Read up on the MSDN Documentation to understand better why this is the case.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 6-Jul-11 10:44am    
Correct, my 5.
More exactly, private or protected methods won't be usable at all; and internal methods are not much needed as the whole interface can be declared internal with the same effect.

--SA
fjdiewornncalwe 6-Jul-11 12:26pm    
Thanks SA
adi007me 6-Jul-11 13:55pm    
Yes. It is not much useful, but is there any other design limitation in .net which doesn't allow this ?
Sergey Alexandrovich Kryukov 6-Jul-11 15:01pm    
If you look at the answer and my comment properly, you will understand that this is not a limitation at all. If you add access modifiers to interface members, it won't be able to change interface usage at all.

When you're are asking about "other design limitations" what do you mean by "this". Listing ***all*** limitations would be like describing all language and CLS from scratch. :-)
--SA
adi007me 7-Jul-11 1:50am    
Thanks SA.
I am also unsure about any design limitation, I was just confirming.

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