C # Reading Notes-Summary of static, virtual, abstract, and abstract members of the natural world

Source: Internet
Author: User

I. Static)

1. Class: static classes cannot be instantiated. They can only be accessed through classes, can be inherited, and can only contain static members.

2. Members: static members can be declared in static classes or non-static classes.

 

Ii. Virtual members)

A virtual member can be overwritten in a derived class and cannot be set to private. After rewriting, in a multi-state application, calling this member always executes the rewritten code in the derived class.

Different from hiding a member (using new): hiding a member in a multi-state application. If the Member is called using a base class variable, the code in the base class is executed. (The interface variables are different, so I will not write them in detail here)

 

Iii. Abstract)

1. Class: the abstract class cannot be instantiated. The only way to use it is inheritance. Abstract classes can contain abstract members or non-Abstract members.

2. member: the abstract member does not execute the code, that is, there is no code body. The code is implemented in the derived class. Abstract members can only be defined in abstract classes.

 

 

Differences between abstract classes and interfaces:

1. A derived class can only inherit from one base class (but can contain multiple abstract classes using one inheritance chain). The opposite interface can inherit from multiple interfaces, but this will not produce much difference.

2. abstract classes can contain abstract members (without code bodies) and non-Abstract members (with code bodies, which can be set to virtual), but interface members must be implemented on their classes.

3. If the abstract class member is not an abstract member, you can set the access class to private, protected, internal, or protected internal members. Interface members cannot define their access. They can only use the default value-public ).

4. The interface cannot contain fields, constructors, destructor, static members, or constants (constants are also static members ).

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.