Mixed Inheritance of interfaces and Classes

Source: Internet
Author: User
Tags ibase mscorlib

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
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.