using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 抽象类
{
//抽象类也是类的一种,故子类继承所有成员
//抽象类中可含有非抽象方法和访问器,至于抽象的方法和访问器,由子类实现
//抽象类的抽象属性,不能是static 、private
abstract class Shape
{
public abstract void GetArea(); //隐式的虚方法 new public ,public abstract 顺序
public abstract void GetPerim();
}
class Rectangle:Shape
{
double width;
double length;
public Rectangle()
{
width = 0;
length = 0;
}
public Rectangle(double width,double length)
{
this.width = width;
this.length = length;
}
public override void GetArea()
{
Console.WriteLine(“矩形的面积为:{0}”, width length);
}
public override void GetPerim()
{
Console.WriteLine(“矩形的周长为:{0}”, 2 (width + length));
}
}
class Circle : Shape
{
double r;
double h;
public Circle(double r,double h)
{
this.r = r;
this.h = h;
}
public override void GetArea()
{
double area = 2 Math.PI r r + 2 Math.PI r h;
Console.WriteLine(“圆柱的面积为:{0}”,area);
}
public override void GetPerim()
{
double volume = Math.PI r r * h;
Console.WriteLine(“圆柱的体积为:{0}”, volume);
}
}
class Program
{
static void Main(string[] args)
{
Rectangle r = new Rectangle(12,10);
r.GetArea();
r.GetPerim();
Circle c = new Circle(1, 1);
c.GetArea();
c.GetPerim();
}
}
}