您的位置:首页 > 其它

定义一个类,封装矩形的长和宽;在定义一个类,继承自定义的这个类,在继承类中根据基类中封装的矩形的长和宽求矩形的面积。

2017-10-12 15:28 363 查看
using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace 封装长方体

{

    class Rectangle

    {

        protected double width;

        protected double height;

        public double Width

        {

            get { return this.width; }

            set { this.width = value; }

        }

        public double Height

        {

            get { return this.height; }

            set { this.height = value; }

        }

        public double getArea()

        {

             return this.height * this.width; 

        }

        public void display()

        {

            Console.WriteLine("长度:{0}", height);

            Console.WriteLine("宽度:{0}", width );

            Console.WriteLine("面积:{0}", getArea ());

        }

    }

    class Program

    {

        static void Main(string[] args)

        {

            Rectangle r = new Rectangle();

            r.Width = 4.5;

            r.Height = 3.5;

            r.display();

            Console.ReadKey();

        }

    }

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐