VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > 编程开发 > c#教程 >
  • C#教程之C#用抽象类定义几何图形

本站最新发布   C#从入门到精通
试听地址  
https://www.xin3721.com/eschool/CSharpxin3721/

using System;
/*using System.Data;*/
namespace tx
{
    abstract class tx
    {
        public double chang;
        public double kuan;
        public double r;
        public double pai;
        public tx(double chang, double kuan)
        {
            this.chang = chang;
            this.kuan = kuan;
           /* this.r = r;
            this.pai = pai*/;
        }
        public abstract void mj();
    }
    class Cfx:tx
    {
        public Cfx(double chang, double kuan) : base(chang,kuan) { }
        public override void mj()
        {
            Console.WriteLine("这个图形是长方形面积为"+chang*kuan+"m^2");
        }
    }
    class zfx : tx
    {
        public zfx(double chang, double kuan) : base(chang,kuan) { }
        public override void mj()
        {
            Console.WriteLine("这个图形是正方形"+chang*kuan+"m^2");
        }
    }
    class Yx : tx
    {
        /*public int k;*/
        
        public Yx(double r) : base(r,0) { }
        public override void mj()
        {
            Console.WriteLine("这图形是圆形面积是"+Math.PI*chang*chang + "m^2");
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Cfx c = new Cfx(10, 12);
            zfx z = new zfx(5, 5);
            Yx y = new Yx(4);
            c.mj();
            z.mj();
            y.mj();
        }
    }
}
相关教程