1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6 7 namespace _111111111111111111111111111 8 { 9 class Test 10 { 11 static void Main() 12 { 13 vehicle ve = new car(100); 14 ve.move(); 15 Console.Read(); 16 } 17 } 18 public class vehicle 19 { 20 protected float speed=111111; 21 public vehicle(float speed) { speed = this.speed+1; } 22 public virtual void move() 23 { 24 Console.WriteLine("我的移动速度是:{0}", this.speed); 25 } 26 } 27 public class car : vehicle 28 { 29 public float speed = 1;//-----子类在这里声明一个字段;就把父类的字段给“覆盖掉了” 30 public car(float speed)//这里speed的值与base(speed)的值都被初始化为100了 31 : base(speed) 32 { 33 speed = this.speed;//这里如果子类没有该字段,就会指向父类的字段(这里也可适用于其他的成员) 34 } 35 public override void move() 36 { 37 Console.WriteLine("我的运行速度是:{0}", this.speed); 38 } 39 } 40 }