//定义一个父类的虚方法
public abstract class Person
{
public abstract double GetArea();
public abstract double GetPrimeter();
}
//继承虚方法父类的子类
public class Circle : Person
{
private double _r;
public double R
{
get { return _r; }
set { _r = value; }
}
public Circle(double r)
{
this.R = r;
}
public override double GetArea()
{
return Math.PI * R * R;
}
public override double GetPrimeter()
{
return Math.PI * R * 2;
}
}
//子类创建一个实例对象并传入一个构造函数对应的参数
Circle c = new Circle(5);
Console.WriteLine($"Circle Area{c.GetArea()},primeter{c.GetPrimeter()}");