1 回答
TA贡献1876条经验 获得超7个赞
使用开发工具为VS2017.针对你问题相关代码如下:
using System;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
Car car = new Car(4,1000,5);
car.Run();
Console.WriteLine(car.ToString());
Console.Read();
}
}
/// <summary>
/// 交通工具类
/// </summary>
public class Vehicle
{
/// <summary>
/// 车轮
/// </summary>
public int wheels { get; }
/// <summary>
/// 车重
/// </summary>
public int weight { get; }
/// <summary>
/// 构造方法
/// </summary>
/// <param name="wheels"></param>
/// <param name="weight"></param>
public Vehicle(int wheels,int weight)
{
this.weight = weight;
this.wheels = wheels;
}
public virtual void Run()
{
Console.WriteLine("running");
}
}
public class Car: Vehicle
{
/// <summary>
/// 车载人数
/// </summary>
public int passenger_load { get; }
public Car(int wheels, int weight,int passenger_load) :base(wheels,weight)
{
this.passenger_load = passenger_load;
}
public override void Run()
{
Console.WriteLine("Car is running");
}
public override string ToString()
{
return $"车轮:{wheels}、车重:{weight}、车载人数:{passenger_load}";
}
}
}
添加回答
举报