使用abstract修饰符声明的类和方法称为抽象类和抽象方法。抽象类不能被示例化,只能作为其他类的基类使用。
abstract class Shapes { public Single side = 0; public Shapes(Single n) { side = n; } abstract public float Area(); } class Square : Shapes { public Square(Single n) : base(n) { side = n; } //Area抽象方法必须被实现 public override float Area() { return side * side; } } class Program { static void Main(string[] args) { Square sq = new Square(12); Console.WriteLine("Area of the square = {0}",sq.Area()); Console.ReadLine(); } }