Create interface with add() and sub() method

Q. Write a java program which creates an interface IterF1 having 2 methods add () and sub(). Create a class which overloads the given methods for addition and subtraction of two numbers respectively.

Answer:

Below example show that the implements the inheritance in the class and overload the interface methods.

IterF1.java

interface IterF1
{
     int a = 50;
     int b = 30;
     void add();
     void sub();
}


Overload_Demo.java

class Overload_Demo implements IterF1
{
     public void add()
     {
          System.out.println("Addition of "+a+" and "+b+" is: "+(a+b));
     }
     public void sub()
     {
          System.out.println("Subtraction of "+a+" and "+b+" is: "+(a-b));
     }
     public static void main(String[] args)
     {
          Overload_Demo obj = new Overload_Demo();
          obj.add();
          obj.sub();
     }
}


Output:

interface overload