接口:
public interface Myinterface {
public void disp(int n);
}
A类:
public class A implements Myinterface {
long sum = 0;
@Override
public void disp(int n) {
for (int i = 1; i <= n; i++) {
sum += i;
}
System.out.println("1+2+3+。。。+n=:" + sum);
}
public static void main(String[] args) {
A a = new A();
a.disp(5);
}
}
B类:
public class B implements Myinterface {
long number = 1;
@Override
public void disp(int n) {
for (int i = 1; i <= n; i++) {
number = number * i;
}
System.out.println("n!=:" + number);
}
public static void main(String[] args) {
B b = new B();
b.disp(4);
}
}