标题:各位帮帮忙,我不是很懂重写这块,在此感激不尽
取消只看楼主
雪月
Rank: 1
来 自:甘肃兰州
等 级:新手上路
帖 子:13
专家分:0
注 册:2012-11-19
结帖率:33.33%
 问题点数:0 回复次数:1 
各位帮帮忙,我不是很懂重写这块,在此感激不尽
public class shap
    {
        public double area;
        public virtual double Area(double S)
        {
            this.area = S;
            return S;
        }
        public double ShowArea()
        {
            Console.WriteLine("面积为{0}",area);
           return area;
        }
        
    }
    public class circle : shap
    {
        double radius;
        public const double PI = 3.1416;
        public circle(double S, double R)
            : base(S)
        {
            // this.area=S;
             this.radius = R;

        }
        public override double Area(double radius)
        {
            double area = PI * radius * radius;
            return Console.ReadLine(area);
 
        }
    }
    public class rectangle : shap
    {
        double length;
        double width;
        public rectangle(double S, double L, double W)
            : base(S)
        {
            this.area=S;
            this.length = L;
            this.width = W;

        }
        public override double Area(double length,double width)
        {
            double area = length * width;
            return Console.WriteLine(area)  ;
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            circle S1=new circle(4);
            S1.Area();

            rectangle  S2= new rectangle (4.6);
            S2.Area();
            
        }
    }
}
搜索更多相关主题的帖子: public double return 
2013-11-28 14:26
雪月
Rank: 1
来 自:甘肃兰州
等 级:新手上路
帖 子:13
专家分:0
注 册:2012-11-19
得分:0 
class Program
    {

        public class shap
        {
            public double area;
            public virtual double Area(double S)
            {
                this.area = S;
                return S;
            }
            public double ShowArea()
            {
                Console.WriteLine("面积为{0}", area);
                return area;
            }
            public virtual double Area()
            {
                return area;
            }
            public shap(double d)
            {
                area = d;
            }
        }
        public class circle : shap          //子类
        {
            double radius;
            public const double PI = 3.1416;
            public circle(double S, double R)    //继承
                : base(S)
            {
                this.area=S;
                this.radius = R;

            }
            public override double Area()
            {
                double area = PI * radius * radius;
                //return Console.ReadLine(area);
                return area;
            }
        }
        public class rectangle : shap        //子类
        {
            double length;
            double width;
            public rectangle(double S, double L, double W)   //继承
                : base(S)
            {
                this.area = S;
                this.length = L;
                this.width = W;

            }
            public override double Area()  //重写
            {
                double area = length * width;
                //return Console.WriteLine(area);
                return area;
            }
        }

        static void Main(string[] args)
        {

            //circle S1 = new circle(" ", 4);//
            circle S1 = new circle(2, 4);
            S1.Area();

            //rectangle S2 = new rectangle(" ", 4, 6);
            rectangle S2 = new rectangle(0, 4, 6);

            S2.Area();
            Console.ReadKey();
        }
    }
}

永不言弃>-<持之以恒
2013-11-28 20:39



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-424343-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.060206 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved