C # abstract class

Source: Internet
Author: User

1. Abstract methods

Methods that have no method body modified by the abstract keyword are called abstract methods.

Grammar:

abstract void shout ();

2. Abstract class

The class that is modified by the abstract keyword is called an abstract class, and the class must have an abstract method (a method that can also be thought of in a class);

Grammar:

Abstract class Animal

{

public void Sex ()

{

Console.WriteLine ("Male");

}

public abstract void name ();

}

To implement an abstract class:

Class Person:animal

{

public override void Name ()

{

Console.WriteLine ("Zhang San");

}
}

3. Interface

Is interface keyword modification, and all the methods inside are abstract methods, which can be called interfaces. (Methods not available in the class for abstract methods)

Grammar:

Interface Animal

{

public void name ();

public void sex ();
}

Implement interfaces (the methods in the interface must all be implemented):

Class Person:animal

{

public void name ()

{

Console.WriteLine ("Zhang San");
}

public void Sex ()

{

Console.WriteLine ("Male");

}

}

C # abstract class

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.