国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

csharp 面向對象編程

2019-11-17 03:20:31
字體:
來源:轉載
供稿:網友

csharp 面向對象編程

using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace Shape{    /**     * 抽象形狀類     */    public abstract class Shape    {        PRivate int edge;        //構造函數         public Shape(int edge)        {            this.edge = edge;        }        //抽象類實現的方法,子類可以重用        public int GetEdge()        {            return this.edge;        }        //抽象方法,子類必須重寫,并在聲明上加上override        public abstract int CalcArea();    }    /**     * 三角形類,繼承自形狀類     */    public class Triangle : Shape    {        private int bottom;        private int height;        //構造函數,構造的同時調用父類指定構造器        public Triangle(int bottom, int height)            : base(3)        {            this.bottom = bottom;            this.height = height;        }        //重寫同名方法        public override int CalcArea()        {            return this.bottom * this.height / 2;        }    }    /**     * 矩形類,繼承自形狀類     */    public class Rectangle : Shape    {        private int bottom;        private int height;        //構造函數,構造的同時調用父類指定構造器        public Rectangle(int bottom, int height)            : base(4)        {            this.bottom = bottom;            this.height = height;        }        //重寫同名方法        public override int CalcArea()        {            return this.bottom * this.height;        }    }    class Program    {        static void Main(string[] args)        {            //測試,可用父類映射子類            Shape triangle = new Triangle(4, 5);            Console.WriteLine(triangle.GetEdge());            Console.WriteLine(triangle.CalcArea());            Shape rectangle = new Rectangle(4, 5);            Console.WriteLine(rectangle.GetEdge());            Console.WriteLine(rectangle.CalcArea());        }    }}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 桦川县| 富阳市| 盐池县| 涟水县| 南华县| 泗阳县| 财经| 太原市| 江津市| 池州市| 新营市| 宁阳县| 新闻| 赤水市| 元朗区| 甘南县| 杨浦区| 石楼县| 曲周县| 孟村| 西宁市| 凤冈县| 锦州市| 巴彦淖尔市| 张家川| 清水县| 鹤山市| 北碚区| 九台市| 乐平市| 永昌县| 贡山| 北安市| 达拉特旗| 钟祥市| 十堰市| 漾濞| 辽阳县| 大渡口区| 辽宁省| 淳安县|