using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 不同形状的面积
{
class Program
{
static void Main(string[] args)
{
Square s = new Square(20, 30);
Circle c = new Circle(10);
s.Area();
c.Area();
Console.ReadKey();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 不同形状的面积
{
class Circle:Figure
{
public Circle(double a):base(a,a)
{ }
public override void Area()
{
Console.WriteLine("圆的面积是:{0}", 3.14 * x * y);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 不同形状的面积
{
abstract class Figure
{
protected double x = 0, y = 0;
public Figure(double a,double b)
{
x = a;
y = b;
}
public abstract void Area();
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 不同形状的面积
{
class Square:Figure
{
public Square(double a, double b) : base(a, b)
{ }
public override void Area()
{
Console.WriteLine("矩形面积是:{0}", x * y);
}
}
}
不同形状的面积
最新推荐文章于 2023-12-04 21:53:43 发布