Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
学ぶ チャレンジ:派生クラス | OOPの基本
C#オブジェクト指向構造

bookチャレンジ:派生クラス

メニューを表示するにはスワイプしてください

Vehicle というクラスが与えられています。それとは別に、CarPlane という2つのクラスもあります。

現在、コードにはエラーがあります。このエラーを修正するには、CarPlaneVehicle を継承するようにする必要があります。

CarPlaneVehicle子クラスとなるようにコードを編集してください。

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

AIに質問する

expand

AIに質問する

ChatGPT

何でも質問するか、提案された質問の1つを試してチャットを始めてください

セクション 4.  2
some-alt