zoukankan      html  css  js  c++  java
  • 问题 A: c#简单类的继承

    题目描述

    编写代码实现:定义了三个类Bird、Mapie、Eagle。其中Bird为抽象类,定义了一个抽象方法Eat()。Mapie类和Eagle类为Bird的派生类。Mapie类中重写了Eat()方法,重载了一个Eat(int time)方法。Eagle类中也重写了Eat()方法。

    输入

    输入time参数的值

    输出

    各个方法的名称

    样例输入

    10

    样例输出

    Mapie eat!
    Mapie eat 10!
    Eagle eat!
    Eagle eat!

    提示

    注意格式!!!

    using System;
    using System.Collections.Generic;
    using System.Text;
    
    namespace 类的继承
    {
        public abstract class Bird
        {
            public abstract void Eat();
        }
        public class Mapie : Bird
        {
            public int t;
            public Mapie(int a)
            {
                this.t = a;
            }
            public override void Eat()
            {
                Console.WriteLine("Mapie eat!");
            }
            public void Eat(int a)
            {
                Console.WriteLine("Mapie eat {0}!", a);
            }
        }
        public class Eagle : Bird
        {
            public int t;
            public Eagle(int a)
            {
                this.t = a;
            }
            public override void Eat()
            {
                Console.WriteLine("Eagle eat!");
            }
            public void Eat(int a)
            {
                Console.WriteLine("Eagle eat!");
            }
        }
    
        class RectangleTester
        {
            static void Main(string[] args)
            {
                int time;
                time = Convert.ToInt32(Console.ReadLine());
                Mapie mapie = new Mapie(time);
                mapie.Eat();
                mapie.Eat(time);
                Eagle eagle = new Eagle(time);
                eagle.Eat();
                eagle.Eat(time);
                Console.ReadKey();
            }
        }
    }
    

      

  • 相关阅读:
    Java消息队列-Spring整合ActiveMq
    控制 Memory 和 CPU 资源的使用
    真的了解js生成随机数吗
    vue原来可以这样上手
    Weex系列一、构建Weex工程
    MS Word 目录排版
    mac上使用终端编译omp代码
    x的平方根
    如何进行特征选择
    单词模式
  • 原文地址:https://www.cnblogs.com/mjn1/p/12618888.html
Copyright © 2011-2022 走看看