hi friends
I want to know about the specification of accessibility modifier for methods inside the interface ?
thanks ....
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
SenthilkumarPosted May 17, 2012, 7:21 AM
As you know the interface can't be instantiated directly, so it needs to be inherited. which means it is default should have some access modifier. It should be public.
VulpesPosted May 16, 2012, 12:57 PM
However, all interface members are explicitly public and so a class (or struct) which implements the interface must provide public implementations of those members.
The only exception to this is if the member is implemented 'explicitly' (i.e. it can only be accessed via an interface reference) in which case no access modifiers are permitted.
For example:
interface IFace
{
void MyMethod();
void YourMethod();
}
class MyClass : IFace
{
public void MyMethod(){}
void IFace.YourMethod(){} // implemented explicitly
}