qq_43412960 2018-11-10 16:30 采纳率: 78.6%
浏览 529
已结题

C#多态问题中的抽象类问题

namespace 实验二
{
class Program
{
static void Main(string[] args)
{
Rectangle Juxing = new Rectangle();
Console.WriteLine("请输入长度:");
Juxing.chang = float.Parse(Console.ReadLine());
Console.WriteLine("请输入宽度:");
Juxing.kuan = float.Parse(Console.ReadLine());
Console.WriteLine("矩形面积:");
Juxing.show();

        Circle yuan = new Circle();

     Console.WriteLine("请输入半径:");
     yuan.r = float.Parse(Console.ReadLine());    
     Console.WriteLine("圆面积:");
     yuan.show();
     Console.ReadLine();




    }

}
 public    class Rectangle : Shape
{
    public float chang;
    public float kuan;
    public float juxingArea()
    {
        return chang * kuan;
    }
    public override void show()
    {
     Console .WriteLine("{0}" ,  juxingArea());
    }

}
public  class Circle : Shape
{
    public float r;
    public double yuanArea()
    {
        return 3.14 * r * r;
    } 
    public override void show()
    {
        Console.WriteLine("{0}", yuanArea());
    }
}

}
namespace 实验二
{
public abstract class Shape
{

    public abstract void show();




}

}这是完整代码
当我执行这个程序的时候 ,输入长宽和半径,不会输出面积,为什么呢

  • 写回答

1条回答 默认 最新

  • threenewbee 2018-11-10 17:01
    关注

    不知道你什么问题,我这里可以输出啊

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace Q710430
    {
        class Program
        {
            static void Main(string[] args)
            {
                Rectangle Juxing = new Rectangle();
                Console.WriteLine("请输入长度:");
                Juxing.chang = float.Parse(Console.ReadLine());
                Console.WriteLine("请输入宽度:");
                Juxing.kuan = float.Parse(Console.ReadLine());
                Console.WriteLine("矩形面积:");
                Juxing.show();
                Circle yuan = new Circle();
                Console.WriteLine("请输入半径:");
                yuan.r = float.Parse(Console.ReadLine());
                Console.WriteLine("圆面积:");
                yuan.show();
                Console.ReadLine();
            }
    
        }
        public abstract class Shape
        {
            public abstract void show();
        }
    
        public class Rectangle : Shape
        {
            public float chang;
            public float kuan;
            public float juxingArea()
            {
                return chang * kuan;
            }
            public override void show()
            {
                Console.WriteLine("{0}", juxingArea());
            }
    
        }
        public class Circle : Shape
        {
            public float r;
            public double yuanArea()
            {
                return 3.14 * r * r;
            }
            public override void show()
            {
                Console.WriteLine("{0}", yuanArea());
            }
        }
    }
    
    

    图片说明

    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题