//定义接口
interface ItoInt
{
int ConvertToInt(string Str);
}
//使用接口
ItoInt a = new doBBS();
int test = a.ConvertToInt( "100 ");
------------------------------------------
interface ItoInt
{
int ConvertToInt(string Str);
}
//使用接口
ItoInt a = new doBBS();
int test = a.ConvertToInt( "100 ");
------------------------------------------
class doBBS implements ItoInt
{
public int ConvertToInt(string Str){}
}
然后再用doBBS()实例化接口
楼主如果学到容器那部分,这种用法很多.
比如:
List是接口,ArrayList,LinketList都实现了List接口的类,经常这样用:
List list=new ArrayList();
list=new LinketList();
又以一个接口类型的引用变量指向new出来的doBBS对向,
这说明doBBS这个类是一个实体类,并且实现了ItoInt接口中的所有抽象方法
这是一种以父类型 引用子类型对象的一个例子,即为多态,
ItoInt a = new doBBS();
int test = a.ConvertToInt( "100 "); a.ConvertToInt( "100 "); 方法在doBBS类中必定被重写了
因为ItoInt 类型变量a 指向了doBBS类型对象,所以引用变量a可以调用doBBS类中重写的
ConvertToInt()方法。