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 {
//declaration
}
class Test implements First {
//statement
}
Example: How to add two numbers using interface in java.
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("Sum is:" + z);
}
public static void main(String args[]) {
Main t = new Main();
t.input();
t.add();
t.display();
}
}
Output:
Enter two numbers:10 20
Sum is:30