using
System;
interface IDrivingLicenceB
... {
void GetLicence();
}
interface IDrivingLicenceA:IDrivingLicenceB
... {
new void GetLicence();
}
class Teacher : IDrivingLicenceA
... {
void IDrivingLicenceA.GetLicence()//完全接口限定名
...{
Console.WriteLine("老师获得A驾执照");
}
void IDrivingLicenceB.GetLicence()//完全接口限定名
...{
Console.WriteLine("老师获得B驾执照");
}
}
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();
((IDrivingLicenceB)t).GetLicence();
((IDrivingLicenceA)t).GetLicence();
}
}
interface IDrivingLicenceB
... {
void GetLicence();
}
interface IDrivingLicenceA:IDrivingLicenceB
... {
new void GetLicence();
}
class Teacher : IDrivingLicenceA
... {
void IDrivingLicenceA.GetLicence()//完全接口限定名
...{
Console.WriteLine("老师获得A驾执照");
}
void IDrivingLicenceB.GetLicence()//完全接口限定名
...{
Console.WriteLine("老师获得B驾执照");
}
}
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();
((IDrivingLicenceB)t).GetLicence();
((IDrivingLicenceA)t).GetLicence();
}
}