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

来源:学生作业帮助网 编辑:作业帮 时间:2024/11/15 17:51:58
Graph定义为抽象类,Draw和Area为抽象方法.两个子类Circle和Rectangle重写两个抽
xTAKA+cNM76$z&8]hx*P  KT7hLYM@2üyyzXAm$N>O?/*ȷK<'?߼`4

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!");
}
}
}
大胖 大胖 大胖