No. In the given code example,
ITest.print
and
Test.print
can have the same implementation in
Usage
. It is perfectly legal to define
Usage.print
as follows:
public class Usage: Testing, ITest {
public override void print() {
Console.WriteLine("Usage.Print");
}
}
The key is to add the
override
modifier to the definition of
Usage.print
. Otherwise,
Usage.print
would (a) hide the implementation of
Test.print
and (b)
Usage
could not be instantiated because it would be lacking the definition of the abstract declaration from
Test.print
.
All of the following invocations default to
Usage.Print
:
static void CallPrint(Usage pUsageInstance) {
pUsageInstance.print();
}
static void CallPrint(Test pTestInstance) {
pTestInstance.print();
}
static void CallPrint(ITest pITestInstance) {
pITestInstance.print();
}
Usage tUsage = new Usage();
CallPrint(tUsage);
CallPrint((Test)tUsage);
CallPrint((ITest)tUsage);