namespace lesson12_work
{
// 接头用到关键字 interface
// 接口与抽象的对比
//相同
// 1都包含可以由子类继承的抽象成员(方法和属性)
// 2都不能被直接实例化,但可以由子类间接实例化(里氏转换)
//不同
// 1抽象类可以有非抽象成员 接口中全部成员必须是抽象
// 2抽象类中可以有私有成员,接口中默认公开的
// 3接口中只能有属性和方法 也可以说只有方法;
// 4接口可以多继承 抽象类不一样
// 5抽象的接口abstract 接口的关键字是interface
//实现接口继承时注意、:
//注意 当一个类继承接口时 有两种实现方法 隐式实现和显示实现
//1 一般用隐式实现(看不出来是继承的接口的)
//2 当一个类继承用多个接口时,并且多个接口中有相同的方法 我们需要用显示的方法实现接口(区分是哪个接口的方法)(没有访问修饰符)
//3 接口实现中 隐式的实现 可以由子类调用 显示的实现必须由本身调用
//举例如下 一个猴子 继承动物 可以跟人一样说话 而且可以战斗
interface IPerson
{
void say ();
}
//相同方法 调用时
//IPerson ip = (Monkey)new Monkey ();
// ip.say ();
// IFighting ifi = (Monkey)new Monkey ();
// ifi.say ();
interface IFighting
{
void fighting ();

void say ();
}

class Animal
{
public void ran ()
{
Console.WriteLine ("run");
}
}

class Monkey:Animal,IPerson,IFighting
{
void IFighting.say ()
{
Console.WriteLine ("hi");
}

void IPerson.say ()
{
Console.WriteLine ("hello");
}

public void fighting ()
{
Console.WriteLine ("战斗");
}
}

class MainClass
{
public static void Main (string[] args)
{
Monkey m = new Monkey ();
m.fighting ();
m.ran ();
IPerson ip = (Monkey)new Monkey ();
ip.say ();
IFighting ifi = (Monkey)new Monkey ();
ifi.say ();
}
}
}

泛型

class Mathe<T>
{
//优点:使用泛型 可以节省瘾参数不同而重复的方法
//缺点:方法内不可用算数运算符 可以用=

public void maxOfTwoNum (T a)
{
Console.WriteLine (a);
}

}

class ExchangeMath<U>:Mathe<string>
{
public void MAX (U u)
{
Console.WriteLine (u);
}
}

//方法中调用

ExchangeMath<string > ch = new ExchangeMath<string > ();

ch.maxOfTwoNum ("hello");
ch.MAX ("123");