CLR notes: 14. Interface

Source: Internet
Author: User
Tags abstract inheritance

Multiple inheritance is not supported by the CLR and all managed languages, and is implemented through an interface simulation

14.1 Implementations of classes and interfaces

Interface definition: A way to specify a name for a set of method signatures.

Class to implement an interface, you must provide implementations of all the methods of the interface.

Even though an abstract class is implemented in its entirety, it can declare an interface method abstract, leaving the interface method to be implemented by a derived class, as follows:

Public interface ITest 

{

void Test ();

Public


abstract class Abstractclass:itest

{public

abstract void Test ();

Public


class Concreateclass:abstractclass

{public

override void Test ()

{
 //coding Implementation;

}

}

14.2 Defining interfaces

The interface can have a method/Event/property, because the latter is essentially a method

There can be no static members (including constants/enumerations) in an interface

Interfaces can be "inherited", which can be thought of as a convention that contains another interface, not a true inheritance

All members under the interface, default to public, without declaring

14.3 Implementation Interface

Implements an interface method that must be marked public, in which case virtual and sealed are not allowed to be overridden by subclasses (when new is not used either).

To show that the calling interface method is marked as virtual, you can override the method in a subclass

If the display is marked as sealed, then you cannot rewrite the

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.