The answer is "Yes" -- interfaces are inherited. However, whether you can omit including interface definitions from a class depends on whether that class wants to have certain interface members as explicit interface implementations.
Let's take this very simple (and silly) example:
public interface IMyInterface
{
void foo();
}
public class A : IMyInterface
{
public void foo()
{
Console.Out.WriteLine("A.foo() executed");
}
}
public class B : A, IMyInterface
{
void IMyInterface.foo()
{
Console.Out.WriteLine("B.foo() executed");
}
}
Since B wants to have the foo() method as an explicit interface implementation, the IMyInterface interface has to be specified as part of its class definition -- even if class A already implements this interface. Inheriting an interface declaration from a base class is not sufficient in this case.
If class B would not have explicit interface implementations, then class B does not need to specify the interface (IMyInterface in this little example) again.
Inheriting an interface from a base class and having some explicit interface implementation for members of that interface can lead to effects which can be surprising at best, and at worst can lead to broken/buggy software.
If you execute the following code sequence:
A obj = new A();
obj.foo();
IMyInterface x = obj;
x.foo();
the output will be
A.foo() executed
A.foo() executed
However, let's now use an object of type B but otherwise keep the code exactly the same:
B obj = new B();
obj.foo();
IMyInterface x = obj;
x.foo();
the output will be somewhat different:
A.foo() executed
B.foo() executed
Why is that so? Remember that class B inherits the implementation of the foo() method from class A. Thus, calling obj.foo()
will still execute the inherited foo() method.
Now, why is then x.foo()
not invoking the foo() implementation provided by class A as well? Or, why is obj.foo()
not invoking the implementation given for foo() in class B?
Because x is a variable of type IMyInterface, thus the explicit interface implementation of the foo() method provided by the object of type B takes precedence when invoking x.foo()
. The variable obj is not of type IMyInterface, hence obj.foo()
will not invoke the explicit interface implementation of the foo() method.
Because of these surprising results it is easy to understand why explicit interface implementations for interfaces which are already implemented by a base class is really a bad idea in most cases. As the saying goes: Just because you can does not mean you should.