using
System;
interface IDrivingLicenceB
... {
void GetLicence();
}
interface IDrivingLicenceA:IDrivingLicenceB
... {
new void GetLicence();
}
class Teacher : IDrivingLicenceA
... {
public void GetLicence()
...{
Console.WriteLine("老师获得A驾执照");
}
}
class Student: IDrivingLicenceB
... {
public void GetLicence()
...{
Console.WriteLine("学生获得B驾执照");
}
}
class Test
... {
static void DriveCar(string name, object o)
...{
IDrivingLicenceB dl = o as IDrivingLicenceB;//强制类型转换
if (dl != null)
...{
Console.WriteLine(name + "开动了卡车");
}
else
...{
Console.WriteLine(name + "没有驾驶证,不能开卡车");
}
}
static void DriveBus(string name, object o)
...{
IDrivingLicenceA dl=o as IDrivingLicenceA;//强制类型转换
if (dl != null)
...{
Console.WriteLine(name+"开动了公共汽车");
}
else
...{
Console.WriteLine(name+"没有驾驶证,不能开公共汽车");
}
}
static void Main()
...{
Teacher t = new Teacher();
DriveBus("老师",t);
DriveCar("老师", t);
Student s = new Student();
DriveBus("学生", s);
DriveCar("学生", s);
}
}
interface IDrivingLicenceB
... {
void GetLicence();
}
interface IDrivingLicenceA:IDrivingLicenceB
... {
new void GetLicence();
}
class Teacher : IDrivingLicenceA
... {
public void GetLicence()
...{
Console.WriteLine("老师获得A驾执照");
}
}
class Student: IDrivingLicenceB
... {
public void GetLicence()
...{
Console.WriteLine("学生获得B驾执照");
}
}
class Test
... {
static void DriveCar(string name, object o)
...{
IDrivingLicenceB dl = o as IDrivingLicenceB;//强制类型转换
if (dl != null)
...{
Console.WriteLine(name + "开动了卡车");
}
else
...{
Console.WriteLine(name + "没有驾驶证,不能开卡车");
}
}
static void DriveBus(string name, object o)
...{
IDrivingLicenceA dl=o as IDrivingLicenceA;//强制类型转换
if (dl != null)
...{
Console.WriteLine(name+"开动了公共汽车");
}
else
...{
Console.WriteLine(name+"没有驾驶证,不能开公共汽车");
}
}
static void Main()
...{
Teacher t = new Teacher();
DriveBus("老师",t);
DriveCar("老师", t);
Student s = new Student();
DriveBus("学生", s);
DriveCar("学生", s);
}
}