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();
            }
        }
    }
    

      

  • 相关阅读:
    Mysql 怎么限制 IP 访问?
    LA2965 n个数中选出最多个数异或和为0
    UVALive 2678 大于s的最短子序列和
    UVA 1193 区间相关(greedy)
    UVA 11992 线段树
    UVA 1400 线段树
    NBUT 1120 线段树
    最大连续区间和的算法总结(转)
    hiho 1015 KMP
    hiho#1128 : 二分·二分查找
  • 原文地址:https://www.cnblogs.com/mjn1/p/12618888.html
Copyright © 2011-2022 走看看