Наследовани51512062е

← разместить еще код

Расшаренный код:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GeometryTasks
{

   abstract public class Animal
    {
        public string AnimalName;
        
        public  Animal(string name)
        {
            AnimalName = name;
        }
        public abstract void Print();
    }

    public class Dog : Animal
    {
        public int speed;
        
        public Dog(int speed, string name) : base(name)
        {
            this.speed = speed;
        }
        public override void Print()
        {
            Console.WriteLine("Скорость:"+ speed);
        }
    }
    public class Cat : Animal
    {
        private int speed;
        private int meow;

        public Cat (int speed,string name,int meow): base(name)
        {
            this.speed = speed;
            this.meow = meow;
        }
        public override void Print()
        {

            Console.WriteLine("Скорость:" + speed);
            Console.WriteLine("Няшность"+ meow);
            Console.WriteLine("");

        }

    }
    public class MainClass
    {
        static void Main()
        {
            List<Animal> lost = new List<Animal>();
            lost.Add(new Cat(5, "Kitti", 50));
            lost.Add(new Dog(60, "Sobaken"));
            foreach (Animal animal in lost)
            {
                animal.Print();
            }
        }

    }
 
}