C # Abstract classes and abstract method implementations

Source: Internet
Author: User

Abstract class
The abstract modifier can be used with classes, methods, properties, indexers, and events.

1. Abstract classes cannot be instantiated.
2. Abstract classes can contain abstract methods and abstract accessors.
3. Abstract classes cannot use the sealed modifier, and this modifier prevents other classes from inheriting from the class.
4. A non-abstract class derived from an abstract class must include all inherited abstract methods and the implementation of an abstract accessor.
5, the abstract method cannot be private.
6. Abstract methods must be declared in an abstract class.
7. The abstract method cannot contain a method body, only the method body can be overridden in a derived class.
8. Static and virtual modifiers cannot be used in abstract method declarations.
9. Overriding the implementation in a derived class, you must add the keyword override.

    Abstract class Count_adstract//Abstraction classes    {        protected string A;        protected string B;        Protected Count_adstract (String A, string b)        {            a = A;            b = b;        }        Public abstract string Count_adstract_method (); Abstract method    }    class count:count_adstract    {public        Count (string A, string b): Base (A, B) {}        Public Override string Count_adstract_method ()//method override        {            return A + B;        }        Class program        {            static void Main (string[] args)            {                count c = new Count ("SSS", "ddd");                Console.WriteLine (C.count_adstract_method ());                Console.readkey ();}}}    

C # Abstract classes and abstract method implementations

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.