C # Abstract and virtual keywords

Source: Internet
Author: User

Http://netstring.cnblogs.com/archive/2005/08/07/209293.html

I have never had much in-depth understanding of the abstract and virtual keywords. Today I am reading msdn and devoted myself to the C # keyword section. I Want To systematically understand the C # keyword. The first one is abstract, on msdn, the abstract modifier can be used with classes, methods, attributes, indexers, and events. Use the abstract modifier in the class declaration to indicate that the class can only be the base class of other classes. The following describes some abstract features: they cannot be instantiated; they can contain abstract methods and abstract accessors; they cannot be modified using the sealed modifier, meaning that the class cannot be inherited; A non-abstract class derived from an abstract class must include all the inherited abstract methods and the implementation of the abstract accessors; use the abstract modifier in a method or attribute declaration to indicate that the method or attribute does not contain an implementation. "Abstract" can modify classes, methods, attributes, indexers, and events. When you see the virtual keyword, there is a question: "virtual" keywords can only modify methods and attributes, but cannot modify classes ~ But I clearly remember that when I was a college teacher talking about C ++, I had a concept called a virtual base class. Does C # Remove this virtual feature? Then I went to Google to find the answer ~ I saw two articles: "C ++ virtual base class" and "in-depth analysis of the C # Inheritance Mechanism", and finally realized that the inheritance mechanism of the two was different. C ++ allows multi-inheritance, while C # only allows the derived class to inherit from one class. The ambiguity arising from multi-Inheritance needs to be solved by the virtual base class, therefore, C ++ has the concept of a virtual base class, while C # does not have the ambiguity arising from inheritance because of single inheritance. Therefore, virtual key modifier classes are not required.

Link:
C ++ virtual base class http://www.yesky.com/496/193996.shtml
In-depth analysis of C # Inheritance Mechanism http://www.yesky.com/SoftChannel/72342380468109312/20030726/1717126.shtml

Related Article

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.