码迷,mamicode.com
首页 > 其他好文 > 详细

虚方法 覆写

时间:2014-07-31 12:13:16      阅读:247      评论:0      收藏:0      [点我收藏+]

标签:color   io   cti   ar   line   new   text   ad   

using System; using System.Collections.Generic; using System.Linq; using System.Text; using graphlei;

namespace graphlei {     /// <summary>     /// 图形类     /// </summary>     public class graph     {         protected string Color;         public graph()         {         }         public graph(string color)         {             this.Color = color;         }         public string GetColor()         {             return Color;         }         public virtual double Getgraph()         {             return 0.0;         }     }     /// <summary>     /// 圆类     /// </summary>     class round : graph     {         double Nameone;         public round()         {         }         public round(string color, double nameone)         {             this.Color = color;             this.Nameone = nameone;         }         /// <summary>         /// 面积         /// </summary>         /// <returns></returns>         public override double Getgraph()         {             return System.Math.PI * Nameone * Nameone;         }     }     /// <summary>     /// 矩形类     /// </summary>     ///     class rectangle : graph     {         protected double Lenght, Width;         public rectangle()         {         }         public rectangle(string color, double Lenght, double Width)         {             this.Color = color;             this.Lenght = Lenght;             this.Width = Width;         }         /// <summary>         /// 面积         /// </summary>         /// <returns></returns>         public override double Getgraph()         {             return Lenght * Width;         }         /// <summary>         /// 周长         /// </summary>         /// <returns></returns>         public double Getrectangle()         {             return (2 * (Lenght + Width));         }     }

    /// <summary>     /// 正方形类     /// </summary>     ///     class square : rectangle     {         protected double side;         public square()         {         }         public square(string Color, double side)         {             this.Color = Color;             this.side = side;         }         public override double Getgraph()         {             return side * side;         }         public double Getsquare()         {             return 2 * (side + side);         }     }    }     class Program     {         static void Main(string[] args)         {             round Myround = new round("红色", 2);             Console.WriteLine("圆颜色 {0},圆的面积 {1}", Myround.GetColor(), Myround.Getgraph());             Console.ReadKey();             rectangle Myrectangle = new rectangle("红色", 1, 2);             Console.WriteLine("矩形颜色 {0},矩形面积{1},矩形的周长{2}",             Myrectangle.GetColor(), Myrectangle.Getgraph(), Myrectangle.Getrectangle());             Console.ReadKey();             square Mysquare = new square("红色", 5);             Console.WriteLine("正方形的颜色{0},正方形的面积{1},正方形的周长{2}",Mysquare.GetColor(),             Mysquare.Getgraph(), Mysquare.Getsquare());             Console.ReadKey();         }

    }

 

虚方法 覆写,布布扣,bubuko.com

虚方法 覆写

标签:color   io   cti   ar   line   new   text   ad   

原文地址:http://www.cnblogs.com/huweijun/p/3879935.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!