1. base关键字主要是为派生类调用基类成员提供一个简写的方法;
2. 举个例子:
using System;
calss Vehicle //定义汽车类
{
int wheels;//公有成员:轮子个数
protected float weight; //保护成员:重量
public Vehicle()
{
;
}
public Vehicle(int w,float g)
{
wheels = w;
weight = g;
}
public void Speak()
{
Console.WriteLine("the w vehicle is speaking!");
}
};
class Car:Vehicle//定义轿车类:从汽车类中继承
{
int passengers; //私有成员:乘客数
public Car(int w,float g,int p):base(w,g)
{
wheels = w;
weight = g;
passengers = p;
}
}
|