转载自:http://blog.csdn.net/sinyu890807/article/details/8986285
1、定义接口
public interface Calculator { //定义计算器接口
int calculator(int x,int y);
}
2、实现接口的功能
public class Add implements Calculator{
@Override
public int calculator(int x, int y) {
return x+y;
}
}
public class Sub implements Calculator {
@Override
public int calculator(int x, int y) {
return x-y;
}
}
3、实现接口
Add add=new Add();
int a=add.calculator(3, 2);
LogUtil.getInstance().debug(Integer.toString(a));
Sub sub=new Sub();
int b=sub.calculator(3,2);
LogUtil.getInstance().debug(Integer.toString(b));