Завдання: Похідні Класи
Дано клас під назвою Vehicle. Окрім нього, існують ще два класи: Car та Plane.
У коді наразі є помилка. Щоб виправити її, потрібно зробити так, щоб класи Car та Plane наслідували клас Vehicle.
Відредагуйте код так, щоб Car та Plane стали дочірніми класами для Vehicle.
index.cs
12345678910111213141516171819202122232425262728293031323334353637using System; public class Vehicle { public int modelYear; public float fuel; } public class Car { public void Drive() { Console.WriteLine("The car is now driving."); } } public class Plane { public void Fly() { Console.WriteLine("The plane is now flying."); } } public class Program { public static void Main(string[] args) { Car c1 = new Car(); Plane p1 = new Plane(); c1.modelYear = 2024; p1.fuel = 6000; Console.WriteLine("Executed Successfully"); } }
Використовуйте символ : у синтаксисі похідного класу для вказання батьківського класу.
index.cs
12345678910111213141516171819202122232425262728293031323334353637using System; public class Vehicle { public int modelYear; public float fuel; } public class Car : Vehicle { public void Drive() { Console.WriteLine("The car is now driving."); } } public class Plane : Vehicle { public void Fly() { Console.WriteLine("The plane is now flying."); } } public class Program { public static void Main(string[] args) { Car c1 = new Car(); Plane p1 = new Plane(); c1.modelYear = 2024; p1.fuel = 6000; Console.WriteLine("Executed Successfully"); } }
Дякуємо за ваш відгук!
Запитати АІ
Запитати АІ
Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат
Awesome!
Completion rate improved to 2.04
Завдання: Похідні Класи
Свайпніть щоб показати меню
Дано клас під назвою Vehicle. Окрім нього, існують ще два класи: Car та Plane.
У коді наразі є помилка. Щоб виправити її, потрібно зробити так, щоб класи Car та Plane наслідували клас Vehicle.
Відредагуйте код так, щоб Car та Plane стали дочірніми класами для Vehicle.
index.cs
12345678910111213141516171819202122232425262728293031323334353637using System; public class Vehicle { public int modelYear; public float fuel; } public class Car { public void Drive() { Console.WriteLine("The car is now driving."); } } public class Plane { public void Fly() { Console.WriteLine("The plane is now flying."); } } public class Program { public static void Main(string[] args) { Car c1 = new Car(); Plane p1 = new Plane(); c1.modelYear = 2024; p1.fuel = 6000; Console.WriteLine("Executed Successfully"); } }
Використовуйте символ : у синтаксисі похідного класу для вказання батьківського класу.
index.cs
12345678910111213141516171819202122232425262728293031323334353637using System; public class Vehicle { public int modelYear; public float fuel; } public class Car : Vehicle { public void Drive() { Console.WriteLine("The car is now driving."); } } public class Plane : Vehicle { public void Fly() { Console.WriteLine("The plane is now flying."); } } public class Program { public static void Main(string[] args) { Car c1 = new Car(); Plane p1 = new Plane(); c1.modelYear = 2024; p1.fuel = 6000; Console.WriteLine("Executed Successfully"); } }
Дякуємо за ваш відгук!