设计一个可在屏幕上作图(点、线矩形、圆等图形)的简单实例,要求是不必真正在屏幕上实现作图,只是有一个示意即可。例如,画一个矩形,不必真正画出矩形,只需输出一句话:This is a rectangle!即可。要用到继承、虚函数、多态、数据的封装、构造函数的实现等各种面向对象程序设计的特性。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace solution6
{
class Graph
{
public virtual void draw()
{
Console.WriteLine("This is a graph!");
}
}
class Rectangle:Graph
{
public override void draw()
{
Console.WriteLine("This is a rectangle!");
}
}
class Circle:Graph
{
public override void draw()
{
Console.WriteLine("This is a circle!");
}
}
class Program
{
static void Main(string[] args)
{
Graph g = new Rectangle();
g.draw();
g = new Circle();
g.draw();
}
}
}