问题 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!

提示

注意格式!!!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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();
        }
    }
}

  

posted @   青衫客36  阅读(289)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示