
package a; public interface InterfaceA {
int method(int n); }
package a; public class ClassA implements InterfaceA { public int method(int n) {
int sum=0;
for (int i = 1; i <=n; i++)
{
sum+=i;
}
System.out.println("1+2+3+......+"+n+"="+sum);
return sum;
} }
package a; public class ClassB implements InterfaceA { public int method(int n) {
int sum=1;
for (int i = 1; i <=n; i++)
{
sum*=i;
}
System.out.println(n+"!="+sum);
return sum;
} }
package a; public class E { public static void main(String[] args) {
InterfaceA a=new ClassA();
InterfaceA b=new ClassB();
a.method(5);
b.method(5); } }