TECH I.S. テックアイエスガイド エディター
Vehicle.cs
Car.cs
Program.cs
using System; namespace MyApplication { class Vehicle // Base class { public string brand = "Ford"; // Vehicle field public void honk() // Vehicle method { Console.WriteLine("Tuut, tuut!"); } } }
using System; namespace MyApplication { class Car : Vehicle // Derived class { public string modelName = "Mustang"; // Car field } }
using System; namespace MyApplication { class Program { static void Main(string[] args) { // Create a myCar object Car myCar = new Car(); // Call the honk() method (From the Vehicle class) on the myCar object myCar.honk(); // Display the value of the brand field (from the Vehicle class) and the value of the modelName from the Car class string output(myCar.brand + " " + myCar.modelName); Console.WriteLine(output); } } }
Try It | Online Web Tutorials