C#题,高手进。

来源:百度知道 编辑:UC知道 时间:2024/06/28 11:55:11
定义一个车辆(Vehicle)基类,具有Run Stop方法,具有Speed(速度),Weight(重量)域。然后以该类为基类,派生出car类。并编程对派生类的功能进行验证。

public class Vehicle
{
float Speed;
float Weight;
public Vehicle()
{
Speed=0;
Weight=0;
}
public void Output()
{
Console.WriteLine(Speed.toString()+" "+Weight.toString());
}
public Run(float a,float b)
{
Speed=a;
Weight=b;
}
public Stop()
{
Speed=0;
Weight=0;
}
}
public class car:Vehicle
{
static void main()
{
Vehicle veh=new Vehicle();
veh.Run(100,100);
veh.Output();
veh.Stop();
veh.Output();
Console.ReadLine();
}
}

using System;

public class Vehicle
{
private int speed;
private int weight;
public Vehicle() { }
public Vehicle(int s, int w)
{
speed = s;
weight = w;
}
public void Run()
{
Console.WriteLine("this is in method run&qu