Haaste: Johdetut Luokat
Luokka nimeltä Vehicle on annettu. Lisäksi on kaksi muuta luokkaa nimeltä Car ja Plane.
Koodissa on tällä hetkellä virhe. Virheen korjaamiseksi sinun täytyy tehdä Car- ja Plane-luokista periytyviä luokkia Vehicle-luokasta.
Muokkaa koodia siten, että Car ja Plane ovat aliluokkia luokasta 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"); } }
Käytä :-symbolia johdetun luokan syntaksissa määrittääksesi kantaluokan.
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"); } }
Kiitos palautteestasi!
Kysy tekoälyä
Kysy tekoälyä
Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme
Awesome!
Completion rate improved to 2.04
Haaste: Johdetut Luokat
Pyyhkäise näyttääksesi valikon
Luokka nimeltä Vehicle on annettu. Lisäksi on kaksi muuta luokkaa nimeltä Car ja Plane.
Koodissa on tällä hetkellä virhe. Virheen korjaamiseksi sinun täytyy tehdä Car- ja Plane-luokista periytyviä luokkia Vehicle-luokasta.
Muokkaa koodia siten, että Car ja Plane ovat aliluokkia luokasta 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"); } }
Käytä :-symbolia johdetun luokan syntaksissa määrittääksesi kantaluokan.
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"); } }
Kiitos palautteestasi!