If IBase is inherited by both the Base class and IA, does Class A inherited from Base and IA inherit the IBase?
Test result: Yes
So does it inherit from the implementation of the Base class or the implementation in IA?
Switch (Who Am I ?)
Case (Base) a: I inherited the implementation of the Base.
Case (IA) a: I inherited from IA implementation
Case (IBase) a: I inherited the implementation from IBase
Case a: whether the methods are declared. If so, the declaration takes priority; otherwise, it is the implementation of the parent class.
This result provides a possibility that the common function of sub-classes is implemented through the parent class, and then applied to all sub-interfaces through the parent interface, and the sub-classes can override the corresponding methods.
Test code:
Code
Namespace ubunturetesting
{
Internal class A: Base, IA, IBase
{
// Methods
Public ();
Void IBase. Write ();
}
Internal class Base: IBase
{
// Methods
Public Base ();
Public void Write ();
}
Public interface IA: IBase
{
}
Public interface IBase
{
// Methods
Void Write ();
}
Internal class InterfaceTesting
{
// Methods
Public InterfaceTesting ();
Public static void Run ();
}
Internal class Program
{
// Methods
Public Program ();
Private static void Main (string [] args );
}
}
IL
. Namespace ubunturetesting
{
. Class private auto ansi beforefieldinit
Extends ubunturetesting. Base
Implements ubunturetesting. IA, ubunturetesting. IBase
{
. Method public hidebysig specialname rtspecialname instance void. ctor () cel managed
{
}
. Method private hidebysig newslot virtual final instance void ubunturetesting. IBase. Write () cel managed
{
. Override ubunturetesting. IBase: Write
}
}
. Class private auto ansi beforefieldinit Base
Extends [mscorlib] System. Object
Implements ubunturetesting. IBase
{
. Method public hidebysig specialname rtspecialname instance void. ctor () cel managed
{
}
. Method public hidebysig newslot virtual final instance void Write () cel managed
{
}
}
. Class public interface abstract auto ansi IA
Implements ubunturetesting. IBase
{
}
. Class public interface abstract auto ansi IBase
{
. Method public hidebysig newslot abstract virtual instance void Write () cel managed
{
}
}
. Class private auto ansi beforefieldinit InterfaceTesting
Extends [mscorlib] System. Object
{
. Method public hidebysig specialname rtspecialname instance void. ctor () cel managed
{
}
. Method public hidebysig static void Run () cel managed
{
}
}
. Class private auto ansi beforefieldinit Program
Extends [mscorlib] System. Object
{
. Method public hidebysig specialname rtspecialname instance void. ctor () cel managed
{
}
. Method private hidebysig static void Main (string [] args) cel managed
{
. Entrypoint
}
}
}
Collapse Types