OJ Problem 3453 c# simple class inheritance

Title description

Writing code implementation: Three classes Bird, Mapie, and Eagle are defined. Among them, Bird is an abstract class, which defines an abstract method Eat(). The Mapie class and Eagle class are derived classes of Bird. The Eat() method is overridden in the Mapie class, and an Eat(int time) method is overloaded. The Eat() method is also rewritten in the Eagle class.

enter

Enter the value of the time parameter

Output

Name of each method

Sample input

10

Sample output

Mapie eat!
Mapie eat 10!
Eagle eat!
Eagle eat!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Security.Cryptography;
using System.IO;
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int time = Convert.ToInt32(Console.ReadLine());
            Mapie m = new Mapie();
            Eagle e = new Eagle();
            m.Eat();
            m.Eat(time);
            e.Eat();
            e.Eat();
        }
    }
    abstract class Bird
    {
        public abstract void Eat();
    }
    class Mapie : Bird
    {
        public override void Eat(){
            Console.WriteLine("Mapie eat!");
        }
        public void Eat(int time)
        {
            Console.WriteLine("Mapie eat {0}!", time);
        }
    }
    class Eagle : Bird
    {
        public override void Eat()
        {
            Console.WriteLine("Eagle eat!");
        }
    }
} 

 

Guess you like

Origin blog.csdn.net/wangws_sb/article/details/105113246