protected float MaxSpeed;
public Vehicle(float speed, float maxSpeed)
public virtual void DisplayInfo()
Console.WriteLine($"Скорость: {Speed} км/ч");
Console.WriteLine($"Максимальная скорость: {MaxSpeed} км/ч");
public Car(float speed, float maxSpeed, string brand)
public override void DisplayInfo()
Console.WriteLine($"Марка: {Brand}");
static void Main(string[] args)
Car myCar = new Car(60, 180, "Toyota");
public Person(string name, int age)
public void DisplayInfo()
Console.WriteLine($"Имя: {Name}");
Console.WriteLine($"Возраст: {Age}");
public Employee(string name, int age, decimal salary)
public new void DisplayInfo()
Console.WriteLine($"Зарплата: {Salary}₽");
static void Main(string[] args)
Employee employee = new Employee("Иван Иванов", 30, 50000);
public virtual void Speak()
Console.WriteLine("Animal speaks");
Console.WriteLine("Dog barks");
static void Main(string[] args)
Animal myAnimal = new Animal();
Animal myPolyDog = new Dog();
public virtual void Draw()
Console.WriteLine("Drawing a shape");
public override void Draw()
Console.WriteLine("Drawing a circle");
public override void Draw()
Console.WriteLine("Drawing a rectangle");
static void Main(string[] args)
Shape myShape = new Shape();
Shape myCircle = new Circle();
Shape myRectangle = new Rectangle();
class NegativeNumberException : Exception
public NegativeNumberException(string message) : base(message) { }
static void CheckNumber(int number)
throw new NegativeNumberException("Число не должно быть отрицательным: " + number);
static void Main(string[] args)
Console.WriteLine("Введите число:");
int number = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Число положительное.");
catch (NegativeNumberException ex)
Console.WriteLine("Ошибка: " + ex.Message);
Console.WriteLine("Ошибка: Введите действительное число.");
Console.WriteLine("Произошла неизвестная ошибка: " + ex.Message);
public sealed class MathUtils
public int Add(int a, int b)
static void Main(string[] args)
MathUtils mathUtils = new MathUtils();
int result = mathUtils.Add(5, 10);
Console.WriteLine($"Результат: {result}");
public virtual void Speak()
Console.WriteLine("Animal speaks");
public class Dog1 : Animal
public override void Speak()
Console.WriteLine("Puppy whines");
static void Main(string[] args)
Animal myDog = new Dog();
Puppy myPuppy = new Puppy();
public virtual void Speak()
Console.WriteLine("Animal makes a sound");
public class Dog2 : Animal
public override void Speak()
Console.WriteLine("Dog barks");
public class Cat : Animal
public override void Speak()
Console.WriteLine("Cat meows");
static void Main(string[] args)
Animal[] animals = new Animal[2];
foreach (Animal animal in animals)