Graph定义为抽象类,Draw和Area为抽象方法.两个子类Circle和Rectangle重写两个抽

来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/24 10:31:36
Graph定义为抽象类,Draw和Area为抽象方法.两个子类Circle和Rectangle重写两个抽Graph定义为抽象类,Draw和Area为抽象方法.两个子类Circle和Rectangle重

Graph定义为抽象类,Draw和Area为抽象方法.两个子类Circle和Rectangle重写两个抽
Graph定义为抽象类,Draw和Area为抽象方法.两个子类Circle和Rectangle重写两个抽

Graph定义为抽象类,Draw和Area为抽象方法.两个子类Circle和Rectangle重写两个抽
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Circle c = new Circle();
Rectangle r = new Rectangle();
double s1,s2;
s1 = c.Area();
c.Draw();
Console.WriteLine("{0}",s1);
s2 = r.Area();
r.Draw();
Console.WriteLine("{0}",s2);
}
}
public abstract class Graph
{
public abstract void Draw();
public abstract double Area();
}
public class Circle :Graph
{
public override double Area()
{
double r = 1;
return r * 3.14 * 3.14;
}
public override void Draw()
{
Console.WriteLine("Circle.Draw!");
}
}
public class Rectangle :Graph
{
public override double Area()
{
double x = 4;
double y = 5;
return x * y;
}
public override void Draw()
{
Console.WriteLine("Rectangle.Draw!");
}
}
}
大胖 大胖 大胖