Hi All,
Here is an example of a method that uses an
interface as a parameter;
interface SVF {
double f(double x);
double getMin();
double getMax();
}
class FCN implements SVF {
public double f(double x) {
return 1.0/x;
}
public double getMin() {
return 1;
}
public double getMax() {
return 10;
}
}
class Print {
public static void ln(SVF s) {
for (double x=s.getMin(); x < s.getMax(); x = x + 0.1)
System.out.println("x="+x+" f(x)="+s.f(x));
}
}
class Test {
public static void main(String args[]) {
FCN s = new FCN();
Print.ln(s);
}
}
|