Java Program to add two numbers using abstract class and method
In this program, You will learn how to add two numbers using abstract class and method in java.
abstract class First {
abstract void input();
abstract void add();
abstract void result();
}
Example: How to add two numbers using abstract class and method in java.
import java.util.Scanner;
abstract class First {
int a, b, s;
abstract void input();
abstract void add();
abstract void result();
Scanner sc = new Scanner(System.in);
}
class Main extends First {
void input() {
System.out.print("Enter two numbers:");
a = sc.nextInt();
b = sc.nextInt();
}
void add() {
s = a + b;
}
void result() {
System.out.print("Sum of two numbers:" + s);
}
public static void main(String args[]) {
Main st = new Main();
st.input();
st.add();
st.result();
}
}
Output:
Enter two numbers:10 20
Sum of two numbers:30