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