1. Abstract methods and declarations of abstract classes1) Abstract class and abstract method declarations must contain abstract2) The declaration of the abstract method has no method body: Public abstract void Fly ();3) Abstract classes and abstract methods before adding public, the default will be private. 4) The declaration of an abstract class is for derivation and inheritance, and is marked as sealed and cannot be inherited. 5) Abstract classes cannot be instantiated, that is, they cannot be used with new, sealed, and must be implemented by the derived class by inheriting its abstract methods6) Abstract classes can contain non-abstract methods7) Original notes:Program.cs:Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;
Using System.Threading.Tasks;
Abstract classes and abstractions
public abstract Fky () {}//default is private
public abstract void fly (); Abstract method declaration No method body
Multiple declarations of abstract classes and abstract methods must contain abstract
The declaration of an abstract class is for derivation and inheritance, and if marked as sealed, you cannot inherit the
Abstract classes cannot be instantiated, they must be implemented by derived classes through inheritance, and therefore cannot be used with new, sealed
Abstract classes can contain non-abstract methods
namespace abstract classes and abstract methods
{
Class Program
{
static void Main (string[] args)
{ }
}
}2. Abstract class and abstract instancePow.cs:Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;
Using System.threading.tasks;namespace abstract class and abstract method instances
{
Public abstract class Pow
{
public abstract void Powmehod (int x,int y);
}
}pow1.cs:using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;
Using System.threading.tasks;namespace abstract class and abstract method instances
{
Class Pow1:pow
{
public override void Powmehod (int x,int y)
{
int POW = 1;
for (int i = 1; I <= y; i++)
{
POW *= x;
}
Console.WriteLine ("The result of exponentiation is:" +pow);
}
}
}Pow2.cs:Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;
Using System.threading.tasks;namespace abstract class and abstract method instances
{
Class Pow2:pow
{
public override void Powmehod (int x, int y)
{Console.WriteLine ("The result of exponentiation:" +system.math.pow (x, y));
}
}
}Program.cs:Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;
Using System.threading.tasks;namespace abstract class and abstract method instances
{
Class Program
{
static void Main (string[] args)
{
Pow pow = new pow (); abstract class not instantiated
Pow1 Pow1 = new Pow1 ();
Pow1. Powmehod (2,10);
Pow2 pow2 = new Pow2 ();
Pow2. Powmehod (2,10);
Console.readkey ();
Abstract method: No implementation of its own.
Virtual method
Common: All can be overrid to the original method of rewriting
}
}
}
C # abstract method and abstract instance--c# Foundation