C # Supplements's trivia (V): Abstract Classes & Interfaces

Source: Internet
Author: User
Abstract class Abstraction:

Abstract classes and abstract methods can be identified with the abstract keyword. is a class or method that is not fully defined. Therefore, you cannot instantiate the operation directly.

Because he is not fully defined, it cannot be sealed with the sealed keyword.

Abstract methods do not include program bodies:

Public abstract class Student    {        //abstract method, excluding program body public abstract void Getstudentid ();//Subclass accessible field prodected int i;// Define the properties of I public int i{    get    {        return I;    }}

Abstract methods for implementing abstract classes in inheriting classes

public class Ah:student    {public        ah (int a)        {            this.i=a;        }        public override void Getstudentid ()        {            Console.WriteLine (i.tostring ());        }    }

Interface interface:

A unified planning interface. Used to define a specification (such as the identification of a method) that needs to be adhered to in a subclass.

Abstract classes cannot be instantiated directly.

The identity of a method, property, or indexer can be defined in an interface.

All members in an interface have the default properties of public and abstract. The methods in the interface must be implemented in subclasses.

A class can ":" Inherit multiple interfaces, and an interface can inherit multiple interfaces.

   Public interface First     {     //indexer     string This[int i]    {         get;         Set;    }    Method    int Fun (int t);    Property    String J    {        get;        Set;    }    }

The above is the C # supplements of the Small Knowledge (V): Abstract class & interface content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!

  • 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.