怎么用java 写一个可以被外部调用并返回参数的接口 最好有个简单的例子 网上的太乱 50
展开全部
public class Calculator implements InterfaceCalculator{
@Override
public String doCalculate(int value) {
return getValue(value);
}
public String getValue(int value)
{
if(value == 0)
return "Nothing";
else
return "Something";
}
public static void main(String args[]) {
InterfaceCalculator calculator = new Calculator();
Displayer displayer = new Displayer(calculator);
displayer.doDisplay();
}
}
================================
public class Displayer {
InterfaceCalculator handler;
public Displayer(InterfaceCalculator handler)
{
this.handler = handler;
}
public void doDisplay()
{
String result = handler.doCalculate(0);
System.out.println(result);
}
}
=================================
public interface InterfaceCalculator {
public String doCalculate(int value);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询