
C#题,高手进。 20
定义一个车辆(Vehicle)基类,具有RunStop方法,具有Speed(速度),Weight(重量)域。然后以该类为基类,派生出car类。并编程对派生类的功能进行验证...
定义一个车辆(Vehicle)基类,具有Run Stop方法,具有Speed(速度),Weight(重量)域。然后以该类为基类,派生出car类。并编程对派生类的功能进行验证。
展开
展开全部
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");
}
public void Stop()
{
Console.WriteLine("this is in method stop");
}
public int Speed
{
get
{
return speed;
}
set
{
speed = value;
}
}
public int Weight
{
get
{
return weight;
}
set
{
weight = value;
}
}
}
public class Car : Vehicle
{
public Car(int s, int w): base(s, w)
{
}
}
public class Mainclass
{
public static void Main()
{
Car c = new Car(50, 100);
Console.WriteLine(c.Speed);
Console.WriteLine(c.Weight);
Console.Read();
}
}
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");
}
public void Stop()
{
Console.WriteLine("this is in method stop");
}
public int Speed
{
get
{
return speed;
}
set
{
speed = value;
}
}
public int Weight
{
get
{
return weight;
}
set
{
weight = value;
}
}
}
public class Car : Vehicle
{
public Car(int s, int w): base(s, w)
{
}
}
public class Mainclass
{
public static void Main()
{
Car c = new Car(50, 100);
Console.WriteLine(c.Speed);
Console.WriteLine(c.Weight);
Console.Read();
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
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();
}
}
{
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();
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询