Java Program to add two numbers using interface


In this program, You will learn how to add two numbers using interface in Java.


interface First { }

class Test implements First { }


Example: How to add two numbers using interface in Java

Run it Now
import java.util.Scanner;

interface First {
    void input();
    void add();
}

class Main implements First {

    int x, y, z;
    Scanner sc = new Scanner(System.in);

    public void input() {
        System.out.print("Enter Two Numbers :");
        x = sc.nextInt();
        y = sc.nextInt();
    }

    public void add() {
        z = x + y;
    }

    void display() {
        System.out.println("\nThe sum is :" + z);
    }

    public static void main(String args[]) {
        Main t = new Main();
        t.input();
        t.add();
        t.display();
    }
}

Output:

Enter Two Numbers :10 30
The sum is :40