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);
}
不是很了解你的意思,接口怎么能被调用呢,里面都是没有实现的方法,怎么放回参数,
我觉得你意思是,用接口接受一个对象,在对象中放回