Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Завдання: Похідні Класи | Основи ООП
C# Понад Базовий Рівень

bookЗавдання: Похідні Класи

Дано клас під назвою Vehicle. Окрім нього, існують ще два класи: Car та Plane.

У коді наразі є помилка. Щоб виправити її, потрібно зробити так, щоб класи Car та Plane наслідували клас Vehicle.

Відредагуйте код так, щоб Car та Plane стали дочірніми класами для Vehicle.

index.cs

index.cs

copy
12345678910111213141516171819202122232425262728293031323334353637
using 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

index.cs

copy
12345678910111213141516171819202122232425262728293031323334353637
using 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"); } }
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 4. Розділ 2

Запитати АІ

expand

Запитати АІ

ChatGPT

Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат

Suggested prompts:

Can you show me the code for the Vehicle, Car, and Plane classes?

What does the error message say?

Can you explain how inheritance works in this context?

Awesome!

Completion rate improved to 2.04

bookЗавдання: Похідні Класи

Свайпніть щоб показати меню

Дано клас під назвою Vehicle. Окрім нього, існують ще два класи: Car та Plane.

У коді наразі є помилка. Щоб виправити її, потрібно зробити так, щоб класи Car та Plane наслідували клас Vehicle.

Відредагуйте код так, щоб Car та Plane стали дочірніми класами для Vehicle.

index.cs

index.cs

copy
12345678910111213141516171819202122232425262728293031323334353637
using 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

index.cs

copy
12345678910111213141516171819202122232425262728293031323334353637
using 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"); } }
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 4. Розділ 2
some-alt