fork download
  1. using System;
  2.  
  3. namespace VehicleHierarchy
  4. {
  5. // Базовый класс транспортного средства
  6. class Vehicle
  7. {
  8. public string Brand { get; set; }
  9. public int Speed { get; set; }
  10.  
  11. public virtual void ShowInfo()
  12. {
  13. Console.WriteLine($"Марка: {Brand}, Скорость: {Speed} км/ч");
  14. }
  15.  
  16. public virtual void Start()
  17. {
  18. Console.WriteLine($"{Brand} начал движение.");
  19. }
  20. }
  21.  
  22. // Класс автомобиля
  23. class Car : Vehicle
  24. {
  25. public int NumberOfDoors { get; set; }
  26.  
  27. public override void ShowInfo()
  28. {
  29. base.ShowInfo();
  30. Console.WriteLine($"Количество дверей: {NumberOfDoors}");
  31. }
  32.  
  33. public override void Start()
  34. {
  35. Console.WriteLine($"{Brand} автомобиль начал движение.");
  36. }
  37. }
  38.  
  39. // Класс велосипеда
  40. class Bike : Vehicle
  41. {
  42. public string Type { get; set; }
  43.  
  44. public override void ShowInfo()
  45. {
  46. base.ShowInfo();
  47. Console.WriteLine($"Тип велосипеда: {Type}");
  48. }
  49.  
  50. public override void Start()
  51. {
  52. Console.WriteLine($"{Brand} велосипед отправился в путь.");
  53. }
  54. }
  55.  
  56. // Класс автобуса
  57. class Bus : Vehicle
  58. {
  59. public int PassengerCapacity { get; set; }
  60.  
  61. public override void ShowInfo()
  62. {
  63. base.ShowInfo();
  64. Console.WriteLine($"Вместимость: {PassengerCapacity} пассажиров");
  65. }
  66.  
  67. public override void Start()
  68. {
  69. Console.WriteLine($"{Brand} автобус отъехал от остановки.");
  70. }
  71. }
  72.  
  73. // Класс грузовика
  74. class Truck : Vehicle
  75. {
  76. public double CargoCapacity { get; set; }
  77.  
  78. public override void ShowInfo()
  79. {
  80. base.ShowInfo();
  81. Console.WriteLine($"Грузоподъемность: {CargoCapacity} тонн");
  82. }
  83.  
  84. public override void Start()
  85. {
  86. Console.WriteLine($"{Brand} грузовик двинулся в путь.");
  87. }
  88. }
  89.  
  90. class Program
  91. {
  92. static void Main()
  93. {
  94. Car myCar = new Car { Brand = "Toyota", Speed = 120, NumberOfDoors = 4 };
  95. Bike myBike = new Bike { Brand = "Giant", Speed = 30, Type = "Горный" };
  96. Bus myBus = new Bus { Brand = "MAN", Speed = 80, PassengerCapacity = 50 };
  97. Truck myTruck = new Truck { Brand = "КамАЗ", Speed = 90, CargoCapacity = 15 };
  98.  
  99. myCar.Start();
  100. myBike.Start();
  101. myBus.Start();
  102. myTruck.Start();
  103. }
  104. }
  105. }
Success #stdin #stdout 0.07s 26640KB
stdin
Standard input is empty
stdout
Toyota автомобиль начал движение.
Giant велосипед отправился в путь.
MAN автобус отъехал от остановки.
КамАЗ грузовик двинулся в путь.