很简单的类继承问题,在线等!
using System;
namespace ConsoleApplication1
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
///
class Vehicle
{
public int wheels;
protected float weight;
public Vehicle()
{;}
public Vehicle(int w,float g)
{
wheels = w;
weight = g;
}
public void show()
{
Console.WriteLine("the wheel of vehicle is:{0}",wheels);
Console.WriteLine("the weight of vehicle is:{0}",weight);
}
}
class Train
{
public int num;
private int passenger;
private float weight;
public Train(){;}
public Train(int n,int p,float w)
{
num =n;
passenger=p;
weight = w;
}
public void Show()
{
Console.WriteLine("the num of train is:{0}",num);
Console.WriteLine("the weight of train is:{0}",weight);
Console.WriteLine("the passenger train car is:{0}",passenger);
}
}
class Car:Vehicle
{
int passenger;
public Car(int w,float g,int p):base(w,g)
{
wheels = w;
weight = g;
passenger = p;
}
//为什么不执行这段代码?
public void Show()
{
Console.WriteLine("the wheel of car is:{0}",wheels);
Console.WriteLine("the weight of car is:{0}",weight);
Console.WriteLine("the passenger of car is:{0}",passenger);
}
}
class Class1
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: 在此处添加代码以启动应用程序
//
Vehicle v1 = new Vehicle(4,5);
Train t1 = new Train();
Train t2 = new Train(10,100,100);
Car c1 = new Car(4,2,4);
v1.show();
t1.Show();
t2.Show();
c1.show();
Console.ReadLine();
}
}
}
为什么调用c1.show()的时候不执行类car里的show()?