In the java programming language, an interface is a reference type, similar to a class, that can contain only constants, method signatures, default methods, static methods, and nested types. Method bodies exist only for default methods and static methods.
Interfaces cannot be instantiated—they can only be implemented by classes or extended by other interfaces.
interface advanceCalculation {
public int divisor_sum(int n) ;
}
class Myclass implements advanceCalculation{
@Override
public int divisor_sum(int n) {
int sum=0;
if(n>1) {
for(int i=1;i<=n;i++) {
if(n%i==0) sum+=i;
}
}
return sum;
}
}
public class Mycalculation {
public static void main(String arg[]) {
Myclass obj=new Myclass();
int s=obj.divisor_sum(6);
System.out.println("The sum of divisor = "+s);
}
}
No comments:
Post a Comment