Cannot implement protected interface member as protected? #7999
Unanswered
JesseRussell411
asked this question in
Q&A
Replies: 2 comments
-
In your default interface case; is that actually an implementation of the interface, or just a coincidental name overlap? |
Beta Was this translation helpful? Give feedback.
0 replies
-
interface IFoo
{
protected int getInternalInt();
public static void Hello(IFoo foo)
{
foo.getInternalInt();//How do we call it here?
}
}
class Foo : IFoo
{
public int getInternalInt()//If this method is protected
{
throw new NotImplementedException();
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm a little confused here. An interface can have a protected member, like this:
But a class that implements the interface cannot make that member's implementation protected like this:
It seems that the implementation has to be public. Then there's no error.
But why does it have to be public when the interface member is protected? The interface doesn't require the member to be public.
In fact, if you add a default implementation to the interface, then you can make the class's implementation protected. No error.
Beta Was this translation helpful? Give feedback.
All reactions